【问题标题】:check the manual that corresponds to your MySQL server version for the right syntax to use near ' '', , '', '', '', '', '', '', '', NOW())' at line 2 [closed]检查与您的 MySQL 服务器版本相对应的手册,以获取正确的语法,以便在 ''', , '', '', '', '', '', '', '', NOW())' 行附近使用2 [关闭]
【发布时间】:2015-01-16 06:27:51
【问题描述】:

我收到这个错误,我是编程新手,如果我错了,请纠正。谢谢

<?

$customername = $_REQUEST["customername"];
//$customername = strtoupper($customername);
//$customername = trim($customername);
$address1=$_REQUEST["address1"];
$address2=$_REQUEST["address2"];
$city  = $_REQUEST["city"];
$state  = $_REQUEST["state"];
$pincode = $_REQUEST["pincode"];
$phonenumber1 = $_REQUEST["phonenumber1"];
$phonenumber2 = $_REQUEST["phonenumber2"];
$emailid1  = $_REQUEST["emailid1"];
$mobilenumber  = $_REQUEST["mobilenumber"];


$sql = "insert into master_customer (id,customername,address1,address2,city,state,pincode,phonenumber1,phonenumber2,emailid1,mobilenumber)
                         values ('','$customername','$address1','$address2','$city','$state','$pincode','$phonenumber1','$phonenumber2','$emailid1','$mobilenumber')";
$exec = mysql_query($sql) or die ("Error in Query".mysql_error());
?>

【问题讨论】:

  • 看起来你有两个逗号并排没有一个空字符串。如果你要将请求值直接放入 SQL 查询中,请确保去掉引号等..(目前这是一个巨大的安全风险)
  • 我认为错误信息不能来自这个语句。这个表上可能有触发器吗?
  • 在错误中指定了 NOW() 部分,这是一个日期插入查询。您提供了不相关的代码。尝试在您的脚本中找到与日期有关的查询。
  • 这不是产生错误的查询,向我们展示实际的查询。
  • 我找不到与该错误有关的任何其他信息,db 表给出错误?我怀疑但是。谢谢

标签: php html mysql


【解决方案1】:

只需使用这一行代替所有代码即可解决您的问题。

$sql = mysql_query("insert into master_customer (id,customername,address1,address2,city,state,pincode,phonenumber1,phonenumber2,emailid1,mobilenumber) VALUES('','".$_REQUEST["customername"]."','".$_REQUEST["address1"]."','".$_REQUEST["address2"]."','".$_REQUEST["city"]."','".$_REQUEST["state"]."','".$_REQUEST["pincode"]."','".$_REQUEST["phonenumber1"]."','".$_REQUEST["phonenumber2"]."','".$_REQUEST["emailid1"]."','".$_REQUEST["mobilenumber"]."')");

不需要这么长的代码。

【讨论】:

    猜你喜欢
    • 2012-06-27
    • 2021-01-26
    • 2014-08-01
    • 2020-02-09
    • 1970-01-01
    • 2021-09-27
    • 1970-01-01
    • 2016-08-06
    • 2015-04-06
    相关资源
    最近更新 更多