# Updating a row in a mysql database

**URL:** <https://forum.kirupa.com/t/updating-a-row-in-a-mysql-database/62224>\
**Category:** programming\
**Created:** [August 26, 2004, 1:48am UTC](https://forum.kirupa.com/t/updating-a-row-in-a-mysql-database/62224 "2004-08-26T01:48:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreamerp](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@dreamerp](https://forum.kirupa.com/u/dreamerp)\
**Post date:** [August 26, 2004, 1:48am UTC](https://forum.kirupa.com/t/updating-a-row-in-a-mysql-database/62224/1 "2004-08-26T01:48:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2004, 2:26am UTC](https://forum.kirupa.com/t/updating-a-row-in-a-mysql-database/62224/2 "2004-08-26T02:26:16Z")

</div>

your SQL would look like this:

```php

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2004, 2:41am UTC](https://forum.kirupa.com/t/updating-a-row-in-a-mysql-database/62224/3 "2004-08-26T02:41:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2004, 5:57am UTC](https://forum.kirupa.com/t/updating-a-row-in-a-mysql-database/62224/4 "2004-08-26T05:57:44Z")

</div>

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

SQL Code

```php

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
