tomasd Posted July 26, 2007 Share Posted July 26, 2007 Hi, I'm trying to add some data to my table. I'm trying to insert into table "dev", column "Jul_25_07" a variable "$price" in the row where column "flight" is equals to variable "$time" something like this: $sql_insert = "INSERT INTO dev (Jul_25_07) VALUES ('$price') WHERE flight = $time"; what is the correct syntax to use? Link to comment https://forums.phpfreaks.com/topic/61832-solved-help-mysql-insert-query/ Share on other sites More sharing options...
DeadEvil Posted July 26, 2007 Share Posted July 26, 2007 $sql_insert = mysql_query("INSERT INTO dev (Jul_25_07) VALUES ('$price') WHERE flight = $time"); if(!$sql_insert): echo "Unable to insert ..."; else: echo "Successfully inserted ..."; endif; Link to comment https://forums.phpfreaks.com/topic/61832-solved-help-mysql-insert-query/#findComment-307908 Share on other sites More sharing options...
tomasd Posted July 26, 2007 Author Share Posted July 26, 2007 I've tried the following: mysql> INSERT INTO dev (Jul_25_07) VALUES ('99.99') WHERE flight = 2007-01-12 09:35:00; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE flight = 2007-01-12 09:35:00' at line 1 My flight column type is datetime Link to comment https://forums.phpfreaks.com/topic/61832-solved-help-mysql-insert-query/#findComment-307916 Share on other sites More sharing options...
DeadEvil Posted July 26, 2007 Share Posted July 26, 2007 try to put a single quote in $time variable eg. INSERT ... WHERE flight = '$time' ... Link to comment https://forums.phpfreaks.com/topic/61832-solved-help-mysql-insert-query/#findComment-307930 Share on other sites More sharing options...
tomasd Posted July 26, 2007 Author Share Posted July 26, 2007 Hi, mysql> INSERT INTO dev (Jul_25_07) VALUES ('99.99') WHERE flight = '2007-01-12 09:35:00' ; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE flight = '2007-01-12 09:35:00'' at line 1 Link to comment https://forums.phpfreaks.com/topic/61832-solved-help-mysql-insert-query/#findComment-307931 Share on other sites More sharing options...
tomasd Posted July 26, 2007 Author Share Posted July 26, 2007 I should have done this: UPDATE dev SET $column = '$price' WHERE flight = '$time' Link to comment https://forums.phpfreaks.com/topic/61832-solved-help-mysql-insert-query/#findComment-308016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.