Jump to content

[SOLVED] Can't get INSERT query to work. Can't see where SYNTAX error is.


vapokerpro

Recommended Posts

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());
?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.