Potatis Posted July 18, 2008 Share Posted July 18, 2008 I can't spot it. This is code I have used several times before. "Fatal error: SQL in /home/.hebrew/dclfilez/domain.com/folder/contact_process.php on line 17" The page is to process a simple contact form. Here is line 17: mysql_query("INSERT INTO contact (time, ip, name, email, message, unread, read) VALUES ('$time', '$ip', '$name', '$email', '$message', '$unread', '$read')") or trigger_error("SQL", E_USER_ERROR); The full code for this processing page" <?php require_once("includes/constants.php"); require_once("includes/connection.php"); $b = time (); $timezone = (date_default_timezone_set("Australia/Sydney")); $time = date ("Y-m-d H:i:s,$b"); $ip = mysql_real_escape_string($_POST['ip']); $name = mysql_real_escape_string($_POST['name']); $email = mysql_real_escape_string($_POST['email']); $message = mysql_real_escape_string($_POST['message']); $unread = "1"; $read = "0"; mysql_query("INSERT INTO contact (time, ip, name, email, message, unread, read) VALUES ('$time', '$ip', '$name', '$email', '$message', '$unread', '$read')") or trigger_error("SQL", E_USER_ERROR); header("Location: index.php"); ?> I hope someone can see what I can't. Link to comment https://forums.phpfreaks.com/topic/115342-solved-cant-spot-the-error-in-1-line/ Share on other sites More sharing options...
kenrbnsn Posted July 18, 2008 Share Posted July 18, 2008 Change this: <?php mysql_query("INSERT INTO contact (time, ip, name, email, message, unread, read) VALUES ('$time', '$ip', '$name', '$email', '$message', '$unread', '$read')") or trigger_error("SQL", E_USER_ERROR); ?> to <?php $q = "INSERT INTO contact (time, ip, name, email, message, unread, read) VALUES ('$time', '$ip', '$name', '$email', '$message', '$unread', '$read')"; $rs = mysql_query($q) or die("Problem with the query: $q on line " . __LINE__ . '<br>' . mysql_error()); ?> Doing this will give you a much better indication as to the error that is causing the problem. Ken Link to comment https://forums.phpfreaks.com/topic/115342-solved-cant-spot-the-error-in-1-line/#findComment-593051 Share on other sites More sharing options...
Potatis Posted July 18, 2008 Author Share Posted July 18, 2008 Thanks for that, it did give me more info, but I can't see what it has a problem with.. It's really weird. I crossed out the IP. It was just a test post. Problem with the query: INSERT INTO contact (time, ip, name, email, message, unread, read) VALUES ('2008-07-18 13:50:00,1216353000', 'xxx.xxx.xxx.xx', 'Herr Moose', '[email protected]', 'HELLO!!!!!!!!', '1', '0') on line 18 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 'read) VALUES ('2008-07-18 13:50:00,1216353000', 'xxx.xxx.xxx.xx', 'Herr Moose ' at line 1 Link to comment https://forums.phpfreaks.com/topic/115342-solved-cant-spot-the-error-in-1-line/#findComment-593067 Share on other sites More sharing options...
btherl Posted July 18, 2008 Share Posted July 18, 2008 Try `read` instead of read (add backticks around it). Link to comment https://forums.phpfreaks.com/topic/115342-solved-cant-spot-the-error-in-1-line/#findComment-593069 Share on other sites More sharing options...
AndyB Posted July 18, 2008 Share Posted July 18, 2008 http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html read is a MySQL reserved word. While `backticks` solve the problem, the better solution would be to avoid using reserved words in field or table names. Link to comment https://forums.phpfreaks.com/topic/115342-solved-cant-spot-the-error-in-1-line/#findComment-593081 Share on other sites More sharing options...
Potatis Posted July 18, 2008 Author Share Posted July 18, 2008 Ahh, thanks so much, btherl and AndyB! That fixed it! Link to comment https://forums.phpfreaks.com/topic/115342-solved-cant-spot-the-error-in-1-line/#findComment-593084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.