vapokerpro Posted September 18, 2009 Share Posted September 18, 2009 Here is my code. It keeps giving me an error that says there is something wrong with my syntax but I've poured over it and can't figure it out so I need some fresh eyes to tell me what I am missing. Thanks in advance. <?php mysql_connect ('localhost','<user>',',<pass>') or die ("Could not connect to MySQL " . mysql_error()); mysql_select_db ('preemployments') or die ("Could not select Database " . mysql_error()); $sql = "INSERT INTO preemployments (create_date, to, emsi_office, fax, from, supplies, tracking, donor_first, donor_last, donor_ssn, test_date, test_time, dpc, dpc_phone, facility_no, mro, test_reason, drug_test, oa, dot_type) VALUES ('$_POST[create_date]', '$_POST[to]', '$_POST[emsi_office]', '$_POST[fax]', '$_POST[from]', '$_POST[supplies]', '$_POST[tracking]','$_POST[donor_first]','$_POST[donor_last]', '$_POST[donor_ssn]', '$_POST[test_date]', '$_POST[test_time]', '$_POST[dpc]', '$_POST[dpc_phone]', '$_POST[facility_no]', '$_POST[mro]', '$_POST[test_reason]', '$_POST[drug_test]', '$_POST[oa]', '$_POST[dot_type]')"; mysql_query ($sql) or die ("Error inserting records in to Table " . mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/174733-solved-cant-get-insert-query-to-work-cant-see-where-syntax-error-is/ Share on other sites More sharing options...
kickstart Posted September 18, 2009 Share Posted September 18, 2009 Hi Personally I would guess that one of the fields you are inserting contains a quote. Try this:- <?php mysql_connect ('localhost','<user>',',<pass>') or die ("Could not connect to MySQL " . mysql_error()); mysql_select_db ('preemployments') or die ("Could not select Database " . mysql_error()); $sql = "INSERT INTO preemployments (create_date, to, emsi_office, fax, from, supplies, tracking, donor_first, donor_last, donor_ssn, test_date, test_time, dpc, dpc_phone, facility_no, mro, test_reason, drug_test, oa, dot_type) VALUES ('".mysql_real_escape_string($_POST['create_date'])."', '".mysql_real_escape_string($_POST['to'])."', '".mysql_real_escape_string($_POST['emsi_office'])."', '".mysql_real_escape_string($_POST['fax'])."', '".mysql_real_escape_string($_POST['from'])."', '".mysql_real_escape_string($_POST['supplies'])."', '".mysql_real_escape_string($_POST['tracking'])."','".mysql_real_escape_string($_POST['donor_first'])."','".mysql_real_escape_string($_POST['donor_last'])."', '".mysql_real_escape_string($_POST['donor_ssn'])."', '".mysql_real_escape_string($_POST['test_date'])."', '".mysql_real_escape_string($_POST['test_time'])."', '".mysql_real_escape_string($_POST['dpc'])."', '".mysql_real_escape_string($_POST['dpc_phone'])."', '".mysql_real_escape_string($_POST['facility_no'])."', '".mysql_real_escape_string($_POST['mro'])."', '".mysql_real_escape_string($_POST['test_reason'])."', '".mysql_real_escape_string($_POST['drug_test'])."', '".mysql_real_escape_string($_POST['oa'])."', '".mysql_real_escape_string($_POST['dot_type'])."')"; mysql_query ($sql) or die ("Error inserting records in to Table $sql " . mysql_error()); ?> All the best Keith Link to comment https://forums.phpfreaks.com/topic/174733-solved-cant-get-insert-query-to-work-cant-see-where-syntax-error-is/#findComment-920888 Share on other sites More sharing options...
PFMaBiSmAd Posted September 18, 2009 Share Posted September 18, 2009 And at least two of your field names are reserved keywords and either need to be changed to something else or enclosed in back-ticks. Link to comment https://forums.phpfreaks.com/topic/174733-solved-cant-get-insert-query-to-work-cant-see-where-syntax-error-is/#findComment-920893 Share on other sites More sharing options...
vapokerpro Posted September 18, 2009 Author Share Posted September 18, 2009 Thank you!!!! I changed the field names in MySQL and on the corresponding pages and it works now. Link to comment https://forums.phpfreaks.com/topic/174733-solved-cant-get-insert-query-to-work-cant-see-where-syntax-error-is/#findComment-920902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.