错误:SQL语法中有错误;

时间:2012-04-30 03:32:57

标签: php mysql

我仍然遇到错误。

  

错误:您的SQL语法出错;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   靠近'comcode,版本,分类,位置,可用性,日期,   客户)第2行的价值观

  <?php
    $host="localhost"; // Host name 
    $username="user1"; // Mysql username 
    $password="test123"; // Mysql password 
    $db_name="inventory"; // Database name 
    $tbl_name="cisco"; // Table name

    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");


    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    mysql_select_db("inventory", $con);


    $addcisco="INSERT INTO cisco
    (critical_spare_id, serial_no, ,comcode, version, classification, location, availability, date, client)
    VALUES ('". $_POST['critical_spare_id'] . "', '" . $_POST['serial_no']. "', '". $_POST['comcode'] . "','". $_POST['version'] . "','". $_POST['classification'] . "','". $_POST['location'] . "', '". $_POST['availability'] . "', '". $_POST['date'] . "', '". $_POST['client'] . "')";


    mysql_query($addcisco,$con);

    if (!mysql_query($addcisco,$con))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record added";

    mysql_close($con);

    ?>

1 个答案:

答案 0 :(得分:2)

您的insert语句中有一个空列名:

(critical_spare_id, serial_no, ,comcode, version,

                              ^