3
Contributors
2
Replies
8
Views
5 Years
Discussion Span
Last Post by gabrielcastillo
0

Here is some help to get you started, its not working code, just a rough outline to get you started. it's simple and basic, but this is how I create simple CRUD forms.

//Connect to db
mysql_connect();

//Select DB
mysql_select_db();

//Catch Post Data and Process
if(isset($_POST['edit'])){
    $profile_id = $_POST['pid'];
    $username = $_POST['username'];
    $fullname = $_POST['fullname'];
    $profile  = $_POST['profile'];

    //Check if content is present
    if(!empty($username)  && !empty($fullname) && !empty($profile)){

        //Update DB
        $q = mysql_query("UPDATE tablename SET username='$username', fullname='$fullname', profile='$profile' WHERE id='$profile_id' LIMIT 1");
        //Create Debug Message
        if(!$q){
            die("Failed to update database check query string or input values.", mysql_error());
        }
        //If query is good, head back to desired page.
        header("Location: /");
        exit;
    }else{
        //Create Empty Error Message
        $error = "Error! No Changes Made";
    }
}

//Create edit form
<form action="" method="POST">
    //Check if has errors
    <?php if(isset($error) != NULL):?>
        <p><?php echo $error; ?></p>
    <?php endif; ?>

    //Create dropdown menu of username with profile id's as values.
    <select name="pid">
        <option value="$profile_id">User1</option>
        <option value="$profile_id">User2</option>
        <option value="$profile_id">User3</option>
    </select>
    <input type="text" name="username" />
    <input type="text" name="fullname" />
    <textarea name="profile" ></textarea>
    <button type="submit" name="edit">Edit User</button>
</form>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.