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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.