clint6998 Posted December 5, 2013 Share Posted December 5, 2013 Title says it all. Here is the error I get: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 '','1-11-111-11-11-11111','',now())' at line 1Upload script looks like this: if($_POST['doSubmit'] == 'Add Distributor') { if (!$link) { die('Could not connect: ' . mysql_error()); } $name_dist=mysql_real_escape_string($_POST['name_dist']); $address_dist=mysql_real_escape_string($_POST['address_dist']); $city_dist=mysql_real_escape_string($_POST['city_dist']); $state_dist=mysql_real_escape_string($_POST['state_dist']); $zip_dist=mysql_real_escape_string($_POST['zip_dist']); $phone_dist=mysql_real_escape_string($_POST['phone_dist']); $ffl_dist=mysql_real_escape_string($_POST['ffl_dist']); $dob_dist=mysql_real_escape_string($_POST['dob_dist']); $sql="INSERT INTO `distributors` (name_dist,address_dist,city_dist,state_dist,zip_dist,phone_dist,ffl_dist,dob_dist,dateAdded_dist) VALUES ('$name_dist','$address_dist','$city_dist','$state_dist','$zip_dist',$phone_dist','$ffl_dist','$dob_dist',now())"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo "<div class=\"msg\">New Distributor Added....done.</div>"; } Form looks like this: <p><?php if(!empty($msg)) { echo $msg[0]; } ?></p> <table width="100%" border="0" cellpadding="5" cellspacing="2" class="myaccount"> <tr> <td style="text-align:right"><form name="addNew" id="addNew" method="post" action="distributors.php">Name of Distributor or Consignor: </td> <td style="text-align:left"><input name="name_dist" type="text" id="name_dist" size="40" class="required"></td> </tr> <tr> <td style="text-align:right">Street: </td> <td style="text-align:left"><input name="address_dist" type="text" size="40" class="required" id="address_dist"></td> </tr> <tr> <td style="text-align:right">City: </td> <td style="text-align:left"><input name="city_dist" type="text" size="40" class="required" id="city_dist"></td> </tr> <tr> <td style="text-align:right">State: </td> <td style="text-align:left"><input name="state_dist" type="text" size="40" class="required" id="state_dist"></td> </tr> <tr> <td style="text-align:right">Zip: </td> <td style="text-align:left"><input name="zip_dist" type="text" size="40" class="required" id="zip_dist"></td> </tr> <tr> <td style="text-align:right">Phone Number: </td> <td style="text-align:left"><input name="phone_dist" type="text" id="phone_dist" size="40" class="required"></td> </tr> <tr> <td style="text-align:right">FFL: </td> <td style="text-align:left"><input name="ffl_dist" type="text" id="ffl_dist" size="40"></td> </tr> <tr> <td style="text-align:right">DOB if no FFL: </td> <td style="text-align:left"><input name="dob_dist" type="text" id="dob_dist" size="40"></td> </tr> <tr> <td colspan="2" style="text-align:center"><input name="doSubmit" type="submit" id="doSubmit" value="Add Distributor"></form></td> </tr> </table> DB table looks like this: `id_dist` int(11) NOT NULL AUTO_INCREMENT, `name_dist` varchar(255) COLLATE latin1_general_ci NOT NULL, `address_dist` text COLLATE latin1_general_ci NOT NULL, `city_dist` varchar(100) COLLATE latin1_general_ci NOT NULL, `state_dist` varchar(2) COLLATE latin1_general_ci NOT NULL, `zip_dist` int(5) NOT NULL, `phone_dist` varchar(255) COLLATE latin1_general_ci NOT NULL, `ffl_dist` varchar(255) COLLATE latin1_general_ci NOT NULL, `dob_dist` varchar(10) COLLATE latin1_general_ci NOT NULL, `dateAdded_dist` date NOT NULL DEFAULT '0000-00-00', PRIMARY KEY (`id_dist`), UNIQUE KEY `name_dist` (`name_dist`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=9 ; Any ideas on why I am getting that error? I have other forms that use this same setup and they work fine so I am not sure what I am missing or have done wrong. Any help would be appreciated.Thanks,Clint Quote Link to comment https://forums.phpfreaks.com/topic/284568-problem-with-php-script-for-uploading-to-db/ Share on other sites More sharing options...
Solution Ch0cu3r Posted December 5, 2013 Solution Share Posted December 5, 2013 You left off a quote before $phone_dist in the query $sql="INSERT INTO `distributors` (name_dist,address_dist,city_dist,state_dist,zip_dist,phone_dist,ffl_dist,dob_dist,dateAdded_dist) VALUES ('$name_dist','$address_dist','$city_dist','$state_dist','$zip_dist','$phone_dist','$ffl_dist','$dob_dist',now())"; ^ missing quote Quote Link to comment https://forums.phpfreaks.com/topic/284568-problem-with-php-script-for-uploading-to-db/#findComment-1461427 Share on other sites More sharing options...
clint6998 Posted December 5, 2013 Author Share Posted December 5, 2013 And that is the one thing that drives anyone crazy...missing something so small yet valuable... Thanks you! Quote Link to comment https://forums.phpfreaks.com/topic/284568-problem-with-php-script-for-uploading-to-db/#findComment-1461428 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.