Jump to content

[SOLVED] Database Insertions


Ken2k7

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?

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.