/    Sign up×
Community /Pin to ProfileBookmark

Problem with PHP script for uploading to DB

Title says it all. Here is the error I get:
[B]
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[/B]

Upload script looks like this:

[code=php]
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>”;
}
[/code]

Form looks like this:

[code=html]
<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>
[/code]

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=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=9 ;
[/CODE]

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

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 06.2013 — looks like you left out a single quote before $phone_dist in the SQL string.
×

Success!

Help @clint6998 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...