I’m trying to update the database using the ajax, but getting some error below error if if see in the console.
INSERT INTO customers(customerName,contactLastName,contactFirstName, phone, addressLine1,addressLine2, city, state, postalCode,country,salesRepEmployeeNumber,creditLimit) VALUES (,,,, ,,,,,,,)
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 ',,, ,,,,,,,)' at line 1
I have hilighted the JS code which contains the prototype ajax code and then the php code which contains the insert details
can you guys help me out in this issue
My site link
http://localhost/fashionsite/customer.php
my js codeenter code here
$('submit_btn').observe('click', function(ev) {
$('customerdetails').request({
method: 'get',
onFailure: function() {
alert("failed");
},
onComplete: function(details){
console.log(details.responseText);
//alert("inserted success fully");
//$("content_updated").update(details.responseText);
}
});
ev.preventDefault();
});
my php code
<?php
include 'config.php';
include 'opendb.php';
//$sNO = $_POST["sNO"];
//$customerNumber = $_POST["customerNumber"];
$customerNames = $_POST["customerName"];
$contactLastName = $_POST["contactLastName"];
$contactFirstName = $_POST["contactFirstName"];
$phone = $_POST["phone"];
$addressLine1 = $_POST["addressLine1"];
$addressLine2 = $_POST["addressLine2"];
$city = $_POST["city"];
$state = $_POST["state"];
$postalCode = $_POST["postalCode"];
$country = $_POST["countryText"];
$salesRepEmployeeNumber = $_POST["salesRepEmployeeNumber"];
$creditLimit = $_POST["creditLimit"];
/*echo $customerNumber .'<br/>'. $customerName .'<br/>'. $contactLastName .'<br/>'. $contactFirstName .'<br/>'. $phone .'<br/>'. $addressLine1 .'<br/>'. $addressLine2 .'<br/>'. $city .'<br/>'. $state .'<br/>'. $postalCode .'<br/>'. $country .'<br/>'. $salesRepEmployeeNumber .'<br/>'. $creditLimit;*/
$sql = "INSERT INTO customers(customerName,contactLastName,contactFirstName, phone, addressLine1,addressLine2, city, state, postalCode,country,salesRepEmployeeNumber,creditLimit) VALUES ($customerNames,$contactLastName,$contactFirstName,$phone, $addressLine1,$addressLine2,$city,$state,$postalCode,$country,$salesRepEmployeeNumber,$creditLimit)";
print $sql;
//echo $sql .'<br/><br/><br/><br/>';
if (!mysql_query($sql,$conn))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
?>
I have hilighted the JS code which contains the prototype ajax code and then the php code which contains the insert details
You send
GETrequest, but try in php get values from$_POSTarray. So then in sql you get'VALUES (,,,, ,,,,,,,)'and it is cause of error.