Updating a row in a mysql database

Hey All,

I currently have a document that I want to update a certain row in my Mysql Database. First I have cleared certain values, but it ends up deleting all of the posts text, etc…
$postTXT=$r[‘postTXT’];
$posterNAME=$r[‘poster’];
$postTITLE=$r[‘posttitle’];

So I want it to update it according to the message which is automatically generated and is a primary key. It is $msgId which refers to the exact name of the row in the database. To go to the editing page, there is a link which is edit.php/$msgId but it really doesn’t edit the $msgId. Anybody know how to select the right row according to the $msgId ?

-Peter

your SQL would look like this:


UPDATE table_name
SET column_name = new_value
WHERE column_name = $msgID;

Would I replace the new_value with $postinfo like $msgTxt or something like that? and I would repeat those?

If you wanted to update multiple fields within a row I’d go with something like this:

SQL Code


UPDATE table_name
SET field_one='$var1', field_two='$var2', field_three='$var3'
WHERE row_id='$msgId' LIMIT 1

It’ll only update your unique row id ($msgId) and it’ll restrict the query to one row just in case the unique id isn’t so unique (Better safe than sorry).

Hope this helps