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()); } Quote Link to comment 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. Quote Link to comment 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', '' Quote Link to comment 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) . "');"); Quote Link to comment Share on other sites More sharing options...
garydt Posted October 3, 2007 Author Share Posted October 3, 2007 tried that, it didn't work. Quote Link to comment 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) . "');"); Quote Link to comment Share on other sites More sharing options...
garydt Posted October 3, 2007 Author Share Posted October 3, 2007 Success! thanks alot 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.