jsquarepants Posted October 12, 2010 Share Posted October 12, 2010 This is very simple, I just want to log the post data. My other code does not seem to have this problem. I know I am missing something obvious. $sql = "INSERT INTO blog_entries (title, content, category, teaser, entry_time) VALUES ('$title', '$content', '$category', '$teaser', now())"; 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 '')' at line 2 <?php include("includes/dbconnect.php"); $DebugText = "Record Post Data: "; foreach($_POST as $k => $v) { $DebugText =+ "'" . $k . "' = " . $v; } $DebugText = mysql_real_escape_string($DebugText); $sql = "INSERT INTO debug_log (DebugText) VALUES ('$DebugText')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } ?> <html> <head><title>Login</title></head> <body> <form action="login_debug.php" method="post"> <table width="300" border="0" cellspacing="0" cellpadding="2"> <tr><td>User Name:</td><td><input type="text" name="UserName" /></td></tr> <tr><td>Password:</td><td><input type="password" name="PassWord" /></td></tr> <tr><td colspan="2"><center><input type="submit" value="Login" /></center></td></ tr> </table> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/215671-error-in-your-sql-syntax/ Share on other sites More sharing options...
Pikachu2000 Posted October 12, 2010 Share Posted October 12, 2010 When you echo your query string, do the values appear to be what you'd expect them to be? Link to comment https://forums.phpfreaks.com/topic/215671-error-in-your-sql-syntax/#findComment-1121346 Share on other sites More sharing options...
sasa Posted October 12, 2010 Share Posted October 12, 2010 line $DebugText =+ "'" . $k . "' = " . $v; must be $DebugText .= "'" . $k . "' = " . $v; Link to comment https://forums.phpfreaks.com/topic/215671-error-in-your-sql-syntax/#findComment-1121425 Share on other sites More sharing options...
Faks Posted October 12, 2010 Share Posted October 12, 2010 $sql = "INSERT INTO blog_entries (title, content, category, entry_time ,teaser) VALUES ('$title', '$content', '$category','".now()."','$teaser')"; Should help Link to comment https://forums.phpfreaks.com/topic/215671-error-in-your-sql-syntax/#findComment-1121441 Share on other sites More sharing options...
PFMaBiSmAd Posted October 12, 2010 Share Posted October 12, 2010 now() is a mysql function and belongs inside the query. Link to comment https://forums.phpfreaks.com/topic/215671-error-in-your-sql-syntax/#findComment-1121447 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.