George Botley Posted July 24, 2009 Share Posted July 24, 2009 I am being faced with the irritating 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 'to, from, from_email, subject, message, date, time) VALUES ('','George Botlet',' at line 1 Below is the code... I have extracted the person I am sending the message to, and then want to manipulate the data to insert it into the messages table.... Any ideas as to why I am being given that error? Below is the code... $query = "SELECT * FROM team_members WHERE assignment='$assignment' AND team='$team'"; $qry = mysql_query($query) or die ("Could not match data because ".mysql_error()); while($row = mysql_fetch_array($qry)) { $to_contact = $row['name']; $to_email = $row['email']; $to_subject = "$q5d"; $to_message = "$q6"; $today = date("Y-m-d"); $time = date("g:i a"); } //Send Message To Relevant Person $sql="INSERT INTO team_messages (to, from, from_email, subject, message, date, time) VALUES ('$to_contact','$name','$email', '$to_subject', '$to_message', '$today', '$time')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "1 record added"; Link to comment https://forums.phpfreaks.com/topic/167265-solved-insert-into-error/ Share on other sites More sharing options...
Mark Baker Posted July 24, 2009 Share Posted July 24, 2009 If you're using MySQL reserved words as column names, you have to reference them in backticks, e.g. `from` Link to comment https://forums.phpfreaks.com/topic/167265-solved-insert-into-error/#findComment-881920 Share on other sites More sharing options...
Bricktop Posted July 24, 2009 Share Posted July 24, 2009 Yes, both "To" and "From" are MySQL reserved words. (http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-1.html for full list) but as Mark says they are permitted if you use the backtick to identify them. Link to comment https://forums.phpfreaks.com/topic/167265-solved-insert-into-error/#findComment-881928 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.