herghost Posted January 15, 2012 Share Posted January 15, 2012 Im sure this is simple, but I cannot see what my problem is! I am hitting an error on my insert query Error: 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 '1' at line 1 I know the output of $user_id is 1, so my error is on $mysavepath $mysavepath = $folder.'/'.$worldname.'_'.date("dMjY"); echo $mysavepath; $savepath = mysql_query("INSERT INTO saves (user_id,savepath) VALUES ('$user_id','$mysavepath')"); echo '<br>'.$savepath; if(!mysql_query($savepath)) { die('<br>Error: ' . mysql_error()); } however it all echos out ok? 188ea678f0dcdc8252aeb15e3c910408/world_15Jan152012 1 Error: 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 '1' at line 1 Can anyone see the problem? Cheers Dave Quote Link to comment https://forums.phpfreaks.com/topic/255063-simple-insert-query-error/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 15, 2012 Share Posted January 15, 2012 if(!mysql_query($savepath)) ^^^ That logic is wrong. $savepath is the result from a mysql_query() statement (a bool true/1 in this case.) You cannot put a result from one query into another mysql_query() statement. The mysql_query() statement expects an SQL query string. Quote Link to comment https://forums.phpfreaks.com/topic/255063-simple-insert-query-error/#findComment-1307854 Share on other sites More sharing options...
litebearer Posted January 15, 2012 Share Posted January 15, 2012 might try... $mysavepath = $folder.'/'.$worldname.'_'.date("dMjY"); $query = "INSERT INTO saves (user_id,savepath) VALUES ('$user_id','$mysavepath')"; echo $query; $result = mysql_query($query) or die('<br>Error: ' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/255063-simple-insert-query-error/#findComment-1307857 Share on other sites More sharing options...
herghost Posted January 15, 2012 Author Share Posted January 15, 2012 if(!mysql_query($savepath)) ^^^ That logic is wrong. $savepath is the result from a mysql_query() statement (a bool true/1 in this case.) You cannot put a result from one query into another mysql_query() statement. The mysql_query() statement expects an SQL query string. might try... $mysavepath = $folder.'/'.$worldname.'_'.date("dMjY"); $query = "INSERT INTO saves (user_id,savepath) VALUES ('$user_id','$mysavepath')"; echo $query; $result = mysql_query($query) or die('<br>Error: ' . mysql_error()); Thanks to both! Sorted out my logic (as litebearers post) Still showing the error but saving as well, that will do for now, until I put all my components together. Quote Link to comment https://forums.phpfreaks.com/topic/255063-simple-insert-query-error/#findComment-1307859 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.