Jump to content

Inserting values into tables


aman1649

Recommended Posts

Hey guys, I am kind of new to php but I am stuck on this question.  I have a mySQL database and table set up called members.  I have some data in the table and I want to be able to add certain things to a paticular row in the table based off the ID number of the row.  One of the values of the table is an auto incremeted ID number.  I want to add a text value called message to a specified ID number.  How do I go about doing that.  I have this code already but it doesn't seem to work.

 

$sql = "INSERT INTO members (message) VALUES ('$_POST[message]',(SELECT id FROM members WHERE id='$_POST[id]'))";

 

Any Ideas?  Thanks

Link to comment
https://forums.phpfreaks.com/topic/223535-inserting-values-into-tables/
Share on other sites

"UPDATE table_name SET column_name='$newValue' WHERE id='$id'";

 

Right on, what volatileboy said. If you're ever trying to modify a row that already exists, even if it means inserting data into null/empty fields, it has to be update. Insert is only used when a completely new row is being created.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.