cordoprod Posted April 30, 2008 Share Posted April 30, 2008 Hi. I want to insert something in a mysql db. I get this error message: 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,2,3,4,5,6) VALUES('glenn','glenn','glenn','glenn','glenn','glenn')' at line 1 My syntax looks like this: $new = "INSERT INTO travek_user_cols(1,2,3,4,5,6) VALUES('".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."')"; It looks weird but the $result is a random username. Link to comment https://forums.phpfreaks.com/topic/103542-error-in-mysql-syntax/ Share on other sites More sharing options...
mescal Posted April 30, 2008 Share Posted April 30, 2008 try this $new = "INSERT INTO travek_user_cols(1,2,3,4,5,6) VALUES('$result["online"]','$result["online"]','$result["online"]','$result["online"]','$result["online"]','$result["online"]')"; grtZ mescal Link to comment https://forums.phpfreaks.com/topic/103542-error-in-mysql-syntax/#findComment-530178 Share on other sites More sharing options...
cordoprod Posted April 30, 2008 Author Share Posted April 30, 2008 Then i get this error message: Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /customers/cordoproduction.com/cordoproduction.com/httpd.www/travek/inc/functions.php on line 161 Link to comment https://forums.phpfreaks.com/topic/103542-error-in-mysql-syntax/#findComment-530180 Share on other sites More sharing options...
zenag Posted April 30, 2008 Share Posted April 30, 2008 u have not gvn open bracket before..INSERT $new = ("INSERT INTO travek_user_cols(1,2,3,4,5,6) VALUES('".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."'"); Link to comment https://forums.phpfreaks.com/topic/103542-error-in-mysql-syntax/#findComment-530181 Share on other sites More sharing options...
cordoprod Posted April 30, 2008 Author Share Posted April 30, 2008 That's exactly what i had when i got the first error message Link to comment https://forums.phpfreaks.com/topic/103542-error-in-mysql-syntax/#findComment-530182 Share on other sites More sharing options...
conker87 Posted April 30, 2008 Share Posted April 30, 2008 u have not gvn open bracket before..INSERT $new = ("INSERT INTO travek_user_cols(1,2,3,4,5,6) VALUES('".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."'"); Try: $new = "INSERT INTO travek_user_cols(1,2,3,4,5,6) VALUES('{$result['online']}','{$result['online']}','{$result['online']}','{$result['online']}','{$result['online']}','{$result['online']}')"; Link to comment https://forums.phpfreaks.com/topic/103542-error-in-mysql-syntax/#findComment-530186 Share on other sites More sharing options...
cordoprod Posted April 30, 2008 Author Share Posted April 30, 2008 No, i didn't have to.. Fixed it myself, but one more thing.. This is my function: function RandomUser() { $db = new DbConnector(); $db->connect(); $sql = "SELECT * FROM travek_userstats WHERE has_pic='true' ORDER BY RAND()"; $result = $db->query($sql); $result = $db->fetchArray($result); $sql_2 = "INSERT INTO travek_user_cols(row1,row2,row3,row4,row5,row6) VALUES('".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."')"; $write = $db->query($sql_2); } It works, and uploads to the DB.. But will $result["online"] be the same in all 6 rows? or one random in every row? I want to have a random in every row.. Link to comment https://forums.phpfreaks.com/topic/103542-error-in-mysql-syntax/#findComment-530190 Share on other sites More sharing options...
conker87 Posted April 30, 2008 Share Posted April 30, 2008 It's going to be the same, since it's the same one you're using. Link to comment https://forums.phpfreaks.com/topic/103542-error-in-mysql-syntax/#findComment-530191 Share on other sites More sharing options...
cordoprod Posted April 30, 2008 Author Share Posted April 30, 2008 I fixed it myself:) Thanks Link to comment https://forums.phpfreaks.com/topic/103542-error-in-mysql-syntax/#findComment-530192 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.