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? Quote Link to comment 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; Quote Link to comment 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 Quote Link to comment 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' ... Quote Link to comment 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 Quote Link to comment 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' Quote Link to comment 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.