Page 1 of 1

Update a row

Posted: Fri Jul 11, 2008 5:17 am
by wiggst3r
Hi

I have a script that takes rows from a database and outputs them, in divs, like a table.
I am able to add a row and delete a row, but I'm looking to be able to edit a row, which then updates a particular row's details

At the moment, I'm just clicking 'Edit' and it inserts a row, rather than updates the row I click on to edit.

My code for the form is:

Code: Select all

            echo '<form action="save.php" name="insert_priority" METHOD="post">';
            echo '<table>';
            echo '<td><input class="briefed" type="text" name="briefed"'; if(isset($_POST['briefed'])){echo "value=\"" . $_POST['briefed'] . "\"";}echo ' /></td>';
            echo '<td><input class="job" type="text" name="job"'; if(isset($_POST['job'])){echo "value=\"" . $_POST['job'] . "\"";}echo ' /></td>';
            echo '<td><input class="category" type="text" name="category"'; if(isset($_POST['category'])){echo "value=\"" . $_POST['category'] . "\"";}echo ' /></td>';
            echo '<td><input class="needed" type="text" name="needed"'; if(isset($_POST['needed'])){echo "value=\"" . $_POST['needed'] . "\"";}echo ' /></td>';
            echo '<td><input class="status" type="text" name="status"'; if(isset($_POST['status'])){echo "value=\"" . $_POST['status'] . "\"";}echo ' /></td>';
            echo '<td class="gap"></td>';
            echo '<td class="gap"></td>';
            echo '<td class="save"><input type="image" style="margin-top: 4px;" src="images/sm-tick-box.jpg" height="20" class="save" alt="Submit ">
</td>';
            echo '</table>';
            echo '</form>';
And the code that deals with the database query is:

Code: Select all

$catid = ($_POST['catid']);
$briefed = ($_POST['briefed']);
$job = ($_POST['job']);
$category = ($_POST['category']);
$needed = ($_POST['needed']);
$status = ($_POST['status']);
$orderid = ($_POST['orderid']);
 
 
 
$sql = "INSERT INTO categories (catid, briefed, job, category, needed, status, orderid) VALUES ('', '$briefed', '$job', '$category', '$needed', '$status', '' )";
mysql_query($query);
Does anyone know, how I'd be able to update a rows contents?

Thanks

Re: Update a row

Posted: Fri Jul 11, 2008 7:15 am
by Spartan101
If you mean the SQL Query, it's usually of the format...

UPDATE table_name
SET column = value
WHERE conditions

I always find w3schools is the most useful site if you want to be refreshed of the basics.