Jump to content

Problem with PHP script for uploading to DB


clint6998
Go to solution Solved by Ch0cu3r,

Recommended Posts

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 1

Upload 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

Link to comment
Share on other sites

  • Solution

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.