原型js中的问题

时间:2012-07-30 15:37:39

标签: php javascript sql prototype

我正在尝试使用ajax更新数据库,但如果在控制台中看到,则会收到一些错误,如果有错误。

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

我已经高兴了包含原型ajax代码的JS代码,然后是包含插入细节的php代码

你能帮我解决这个问题

吗?

我的网站链接

http://localhost/fashionsite/customer.php

我的js代码enter 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();
});

我的PHP代码

<?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";

?>

我已经高兴了包含原型ajax代码的JS代码,然后是包含插入细节的php代码

1 个答案:

答案 0 :(得分:2)

您发送GET请求,但尝试使用php从$_POST数组中获取值。那么在sql中你得到'VALUES (,,,, ,,,,,,,)'并且它是错误原因。