jim.davidson Posted April 4, 2007 Share Posted April 4, 2007 I’m running PHP 5.0 MySQL 4.1.21 dreamweaver 8 I get the following insert syntax error, any idea what’s wrong? 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 'main st,apt2,aliquippa,PA,15001,jim davidson,123-456-7890,[email protected],test)' at line 2 // place insert customer info here $insertSQL="INSERT INTO customers (first_name, last_name, address_1, address_2, city, state, zip, contact_name, contact_phone, contact_email, contact_comments) VALUES (".$_SESSION['contact_first_name'].",".$_SESSION['contact_last_name'].",".$_SESSION ['contact_address1'].",".$_SESSION ['contact_address2'].",".$_SESSION ['contact_city'].",".$_SESSION ['contact_state'].",".$_SESSION ['contact_zip'].",".$_SESSION['contact_name'].",".$_SESSION['contact_phone'].",".$_SESSION['contact_email'].",".$_SESSION['contact_comments'].")"; mysql_select_db($database_imcrecycle, $imcrecycle); $Result1 = mysql_query($insertSQL, $imcrecycle) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/45598-solved-insert-syntax-error/ Share on other sites More sharing options...
dough boy Posted April 4, 2007 Share Posted April 4, 2007 You aren't encasing the "input" in single quotes. So ",".$_SESSION ['contact_address1']."," Should be: ",'".$_SESSION ['contact_address1']."'," Quote Link to comment https://forums.phpfreaks.com/topic/45598-solved-insert-syntax-error/#findComment-221445 Share on other sites More sharing options...
jim.davidson Posted April 4, 2007 Author Share Posted April 4, 2007 Thank you so very much that was it, it works, thank you, thank you, thank you where can I read up on this topic I'd like to understand it I'm new to this. I'm and old Clipper programmer trying to learn new skills Quote Link to comment https://forums.phpfreaks.com/topic/45598-solved-insert-syntax-error/#findComment-221459 Share on other sites More sharing options...
dough boy Posted April 4, 2007 Share Posted April 4, 2007 www.mysql.com is a good place to start. A general rule of thumb is that if it is a number, you don't have to "encase" it. If it is anything other than a number or a function i.e. NOW(), you do need to "encase" it. Quote Link to comment https://forums.phpfreaks.com/topic/45598-solved-insert-syntax-error/#findComment-221480 Share on other sites More sharing options...
fenway Posted April 4, 2007 Share Posted April 4, 2007 I'd recommend that you quote everything except mysql functions. Quote Link to comment https://forums.phpfreaks.com/topic/45598-solved-insert-syntax-error/#findComment-221578 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.