garydt Posted October 3, 2007 Share Posted October 3, 2007 Everytime i submit the form i get- 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 ''test', ''' at line 1 Any ideas? Thanks if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $subj = $_POST['subject']; $s = preg_replace ($search, $replace, $subj); $text = $_POST['post']; $p = preg_replace ($search, $replace, $text); $dt = date('d-M-Y'); mysql_select_db($database_elvisdb, $elvisdb); $insertSQL = sprintf("INSERT INTO forum (topic, message) ('" . mysql_real_escape_string($s) . "', '" . mysql_real_escape_string($p) . "'"); mysql_select_db($database_elvisdb, $elvisdb); $Result1 = mysql_query($insertSQL, $elvisdb) or die(mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/71677-mysql-error/ Share on other sites More sharing options...
trq Posted October 3, 2007 Share Posted October 3, 2007 Change this... $Result1 = mysql_query($insertSQL, $elvisdb) or die(mysql_error()); to this... $Result1 = mysql_query($insertSQL, $elvisdb) or die(mysql_error()."<br />".$insertSQL); and post the output. Link to comment https://forums.phpfreaks.com/topic/71677-mysql-error/#findComment-360836 Share on other sites More sharing options...
garydt Posted October 3, 2007 Author Share Posted October 3, 2007 The output is - 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 ''testing123', ''' at line 1 INSERT INTO forum (topic, message) ('testing123', '' Link to comment https://forums.phpfreaks.com/topic/71677-mysql-error/#findComment-360843 Share on other sites More sharing options...
MmmVomit Posted October 3, 2007 Share Posted October 3, 2007 You're missing a close paren and semi-colon at the end of your sql statement $insertSQL = sprintf("INSERT INTO forum (topic, message) ('" . mysql_real_escape_string($s) . "', '" . mysql_real_escape_string($p) . "');"); Link to comment https://forums.phpfreaks.com/topic/71677-mysql-error/#findComment-360850 Share on other sites More sharing options...
garydt Posted October 3, 2007 Author Share Posted October 3, 2007 tried that, it didn't work. Link to comment https://forums.phpfreaks.com/topic/71677-mysql-error/#findComment-360867 Share on other sites More sharing options...
MmmVomit Posted October 3, 2007 Share Posted October 3, 2007 Oops, missed the VALUES clause, too $insertSQL = sprintf("INSERT INTO forum (topic, message) VALUES ('" . mysql_real_escape_string($s) . "', '" . mysql_real_escape_string($p) . "');"); Link to comment https://forums.phpfreaks.com/topic/71677-mysql-error/#findComment-360870 Share on other sites More sharing options...
garydt Posted October 3, 2007 Author Share Posted October 3, 2007 Success! thanks alot Link to comment https://forums.phpfreaks.com/topic/71677-mysql-error/#findComment-360877 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.