www.webdeveloper.com
Results 1 to 2 of 2

Thread: Problem with PHP script for uploading to DB

  1. #1
    Join Date
    Aug 2011
    Posts
    2

    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 (!
    $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:

    HTML Code:
              <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:&nbsp;</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:&nbsp;</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:&nbsp;</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:&nbsp;</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:&nbsp;</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:&nbsp;</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:&nbsp;</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:&nbsp;</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:

    Code:
      `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

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    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

    eBookworm.us

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