Ken2k7 Posted August 22, 2007 Share Posted August 22, 2007 Say I created this table: mysql_query("CREATE TABLE member(id mediumint(, 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? Quote Link to comment https://forums.phpfreaks.com/topic/66264-solved-database-insertions/ Share on other sites More sharing options...
Fadion Posted August 22, 2007 Share Posted August 22, 2007 If this is what u mean: $name = "Ken2k7"; mysql_query("ALTER TABLE member CHANGE name $name VARCHAR(255)"); Quote Link to comment https://forums.phpfreaks.com/topic/66264-solved-database-insertions/#findComment-331430 Share on other sites More sharing options...
Barand Posted August 22, 2007 Share Posted August 22, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66264-solved-database-insertions/#findComment-331433 Share on other sites More sharing options...
Fadion Posted August 22, 2007 Share Posted August 22, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66264-solved-database-insertions/#findComment-331439 Share on other sites More sharing options...
Ken2k7 Posted August 22, 2007 Author Share Posted August 22, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/66264-solved-database-insertions/#findComment-331445 Share on other sites More sharing options...
wheelerc Posted August 23, 2007 Share Posted August 23, 2007 If you want to set ever row in the table to have the same name you can do: "UPDATE table SET name = '$name' WHERE 1" (you probably don't need the WHERE 1 part, but i put it in out of habbit) Quote Link to comment https://forums.phpfreaks.com/topic/66264-solved-database-insertions/#findComment-331447 Share on other sites More sharing options...
teng84 Posted August 23, 2007 Share Posted August 23, 2007 http://w3schools.com/php/php_mysql_update.asp http://w3schools.com/sql/sql_update.asp read those links before asking again i guess the prob is that you really dont know update Quote Link to comment https://forums.phpfreaks.com/topic/66264-solved-database-insertions/#findComment-331450 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.