kurtis Posted September 1, 2006 Share Posted September 1, 2006 im making a messaging system, very simple and easy but i get this 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 'read, sender_ip, text, time) VALUES('0', 'dthdjh', '6', '7', '0', '127.0.0.1', '' at line 1"the code for the mysql query is:[code]$query = mysql_query("INSERT INTO messages (id, subject, sender_id, to_id, read, sender_ip, text, time) VALUES('$msg_id', '$subject', '$id', '$to_id', '$read', '$ip', '$message', now())") or die (mysql_error());[/code]does anyone know how to solve this error?thanks Link to comment https://forums.phpfreaks.com/topic/19396-you-have-an-error-in-your-sql-syntax/ Share on other sites More sharing options...
Caesar Posted September 1, 2006 Share Posted September 1, 2006 Can you please post the code that comes before your DB insertion? Thanks. Link to comment https://forums.phpfreaks.com/topic/19396-you-have-an-error-in-your-sql-syntax/#findComment-84186 Share on other sites More sharing options...
kurtis Posted September 1, 2006 Author Share Posted September 1, 2006 [code]<?phpsession_start();include ('db.php');$to = $_POST['to'];$subject = $_POST['subject'];$message = $_POST['message'];$id = $_SESSION['id'];if ((!$to) || (!$subject) || (!$message)){ echo 'You did not supply the following needed infomation<br>'; if (!$to){ echo 'username-We need to know who the message is going to!<br>'; } if (!$subject){ echo 'subject-You need a subject!<br>'; } if (!$message){ echo 'message-Currect me if im wrong but you are trying to send a message so obviously you need a message!<br>'; } include ('message.php'); exit();}$id_get = mysql_query("SELECT * FROM users WHERE username='$to'") or die (mysql_error());$to_id = mysql_fetch_array($id_get);$no_id = mysql_num_rows($id_get);if($no_id <1){ echo 'the user isnt in our database<br>'; include ('message.php'); exit();}$to_id = $to_id['id'];$msg_id = mysql_insert_id();$ip = getenv('REMOTE_ADDR');$read = '0';$query = mysql_query("INSERT INTO messages (id, subject, sender_id, to_id, read, sender_ip, text, time) VALUES('$msg_id', '$subject', '$id', '$to_id', '$read', '$ip', '$message', now())") or die (mysql_error());?>[/code]if the error is something simple slap me real hard! lol Link to comment https://forums.phpfreaks.com/topic/19396-you-have-an-error-in-your-sql-syntax/#findComment-84192 Share on other sites More sharing options...
craygo Posted September 1, 2006 Share Posted September 1, 2006 well looks like your field names are messed up. Somehwere around to_id. Are your field names correct?? Check to make sure they are, and any spaces you need to put the field names in ticks "`".Ray Link to comment https://forums.phpfreaks.com/topic/19396-you-have-an-error-in-your-sql-syntax/#findComment-84195 Share on other sites More sharing options...
sasa Posted September 1, 2006 Share Posted September 1, 2006 try to change read to `read` Link to comment https://forums.phpfreaks.com/topic/19396-you-have-an-error-in-your-sql-syntax/#findComment-84253 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.