Results 1 to 2 of 2

Thread: Problem with PHP script for uploading to DB

Hybrid View

  1. #1
    Join Date
    Aug 2011

    Question Problem with PHP script for uploading to DB

    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:

    PHP Code:
    if($_POST['doSubmit'] == 'Add Distributor')

    if (!
    'Could not connect: ' mysql_error());

    $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)) {
    'Error: ' mysql_error());
    "<div class=\"msg\">New Distributor Added....done.</div>";             

    Form looks like this:

    HTML Code:
    	  				   if(!empty($msg)) {
    	  					 	 echo $msg[0];
    	  					 } ?></p>
          <table width="100%" border="0" cellpadding="5" cellspacing="2" class="myaccount">
              <td style="text-align:right"><form name="addNew" id="addNew" method="post" action="distributors.php">Name of Distributor or Consignor:&nbsp;</td>
              <td style="text-align:left"><input name="name_dist" type="text" id="name_dist" size="40" class="required"></td>
            	<td style="text-align:right">Street:&nbsp;</td>
              <td style="text-align:left"><input name="address_dist" type="text"  size="40" class="required" id="address_dist"></td>
            	<td style="text-align:right">City:&nbsp;</td>
              <td style="text-align:left"><input name="city_dist" type="text"  size="40" class="required" id="city_dist"></td>
            	<td style="text-align:right">State:&nbsp;</td>
              <td style="text-align:left"><input name="state_dist" type="text"  size="40" class="required" id="state_dist"></td>
            	<td style="text-align:right">Zip:&nbsp;</td>
              <td style="text-align:left"><input name="zip_dist" type="text"  size="40" class="required" id="zip_dist"></td>
            	<td style="text-align:right">Phone Number:&nbsp;</td>
              <td style="text-align:left"><input name="phone_dist" type="text" id="phone_dist" size="40" class="required"></td>
            	<td style="text-align:right">FFL:&nbsp;</td>
              <td style="text-align:left"><input name="ffl_dist" type="text" id="ffl_dist" size="40"></td>
            	<td style="text-align:right">DOB if no FFL:&nbsp;</td>
              <td style="text-align:left"><input name="dob_dist" type="text" id="dob_dist" size="40"></td>
            	<td colspan="2" style="text-align:center"><input name="doSubmit" type="submit" id="doSubmit" value="Add Distributor"></form></td>
    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`)
    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.



  2. #2
    Join Date
    Aug 2004
    looks like you left out a single quote before $phone_dist in the SQL string.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles