Jump to content

Recommended Posts

Say I created this table:

 

mysql_query("CREATE TABLE member(id mediumint(8), name varchar(255), age int(3), location varchar(255), goals longtext)") or die(mysql_error());

 

Say I just want to change the name column in that table, can I do this:

 

$name = "Ken2k7"

mysql_query("INSERT INTO member (name) VALUES ('$name')") or die(mysql_error());

 

And if so, should it says VALUES or VALUE?

Link to comment
https://forums.phpfreaks.com/topic/66264-solved-database-insertions/
Share on other sites

That will enter a new name. If you want to change an existing name then you need an update query.

 

UPDATE table SET name = '$name' WHERE id = $kensID.

 

With an insert query it's always VALUES, even if there is only the one as in your example

That will enter a new name. If you want to change an existing name then you need an update query.

 

Actually it will change the column name, but probably i got this wrong as i thought he wanted to change the column name with code, while he's only trying to update a record.

That will enter a new name. If you want to change an existing name then you need an update query.

 

UPDATE table SET name = '$name' WHERE id = $kensID.

 

With an insert query it's always VALUES, even if there is only the one as in your example

Oh so what if I want to update a really long table? Like what if I wanted to update all the values in the table I have in the first post?

 

Is there a way such that I don't have to write that sentence 5 times?

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.