mike12255 Posted June 17, 2009 Share Posted June 17, 2009 I can never fix these/get them right.... What is wrong with this one: $sql = "INSERT INTO pages (info) VALUES ('$info') WHERE page = '".$page."' "; it outputs this: 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 page = 'wine'' at line 1 i though i had it so that one " didnt actually cant as apart of the query Quote Link to comment https://forums.phpfreaks.com/topic/162663-solved-whats-wrong-with-my-query/ Share on other sites More sharing options...
adamlacombe Posted June 17, 2009 Share Posted June 17, 2009 Try: $sql = "INSERT INTO pages (info) VALUES ('$info') WHERE page='$page'"; Quote Link to comment https://forums.phpfreaks.com/topic/162663-solved-whats-wrong-with-my-query/#findComment-858466 Share on other sites More sharing options...
mike12255 Posted June 17, 2009 Author Share Posted June 17, 2009 i've tried that query before and just again, im getting the same error Quote Link to comment https://forums.phpfreaks.com/topic/162663-solved-whats-wrong-with-my-query/#findComment-858468 Share on other sites More sharing options...
adamlacombe Posted June 17, 2009 Share Posted June 17, 2009 hmm... it has something to do with the: WHERE page='".$page."' im not sure... sorry. Quote Link to comment https://forums.phpfreaks.com/topic/162663-solved-whats-wrong-with-my-query/#findComment-858471 Share on other sites More sharing options...
mike12255 Posted June 17, 2009 Author Share Posted June 17, 2009 no im talking about the query you posted Quote Link to comment https://forums.phpfreaks.com/topic/162663-solved-whats-wrong-with-my-query/#findComment-858473 Share on other sites More sharing options...
adamlacombe Posted June 17, 2009 Share Posted June 17, 2009 yeah I know. It must have something to do with the WHERE part of it. everything else seem to be correct. Quote Link to comment https://forums.phpfreaks.com/topic/162663-solved-whats-wrong-with-my-query/#findComment-858476 Share on other sites More sharing options...
adamlacombe Posted June 17, 2009 Share Posted June 17, 2009 try: $sql = "INSERT INTO pages (info) VALUES ('$info') WHERE page = '{".$page."}' "; Quote Link to comment https://forums.phpfreaks.com/topic/162663-solved-whats-wrong-with-my-query/#findComment-858479 Share on other sites More sharing options...
mike12255 Posted June 17, 2009 Author Share Posted June 17, 2009 nope, 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 page = '{wine}'' at line 1 thanks for the effort though Quote Link to comment https://forums.phpfreaks.com/topic/162663-solved-whats-wrong-with-my-query/#findComment-858481 Share on other sites More sharing options...
adamlacombe Posted June 17, 2009 Share Posted June 17, 2009 thanks, sorry i couldn't help. im sure someone else can. hope you get it fixed soon! -Adam Quote Link to comment https://forums.phpfreaks.com/topic/162663-solved-whats-wrong-with-my-query/#findComment-858482 Share on other sites More sharing options...
DavidAM Posted June 17, 2009 Share Posted June 17, 2009 Did you escape the strings ($info and $page) before you put them in the $sql statement? Add echo '|' . $sql . '|'; just before you execute the query. The vertical bars will help isolate the actual query string. Post what is there and we'll get a better idea of the problem. There may be something in one of the variables ($info or $page) that the server is interpreting. Quote Link to comment https://forums.phpfreaks.com/topic/162663-solved-whats-wrong-with-my-query/#findComment-858485 Share on other sites More sharing options...
mike12255 Posted June 17, 2009 Author Share Posted June 17, 2009 |INSERT INTO pages (info) VALUES (' testdfasddfasdfsfadsfg ') WHERE page = '{wine}' | 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 page = '{wine}'' at line 1 I added a <br> after the last | in your code Quote Link to comment https://forums.phpfreaks.com/topic/162663-solved-whats-wrong-with-my-query/#findComment-858488 Share on other sites More sharing options...
DavidAM Posted June 17, 2009 Share Posted June 17, 2009 Sorry, what am I thinking? INSERT does not allow a WHERE clause. The record will be ADDED to the database. Are you trying to UPDATE an existing row? $sql = "UPDATE pages SET info = '" . $info . "' WHERE page = '".$page."' "; or are you trying to INSERT a new row? $sql = "INSERT INTO pages (info, page) VALUES ('" . $info . "', '" . $page . "'); Quote Link to comment https://forums.phpfreaks.com/topic/162663-solved-whats-wrong-with-my-query/#findComment-858510 Share on other sites More sharing options...
mike12255 Posted June 17, 2009 Author Share Posted June 17, 2009 ...what am i thinking, i ment update thanks. Quote Link to comment https://forums.phpfreaks.com/topic/162663-solved-whats-wrong-with-my-query/#findComment-858524 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.