-3

我尝试从表单输入向 MySQL 数据库添加值,它曾经工作正常,最近它开始给我这个错误:

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 'group) VALUES('כיריים על השיש','1','9')' 附近使用正确的语法。

我的代码是:

if (isset($_POST['cat_name']))
{       
    $cat_name = mysql_real_escape_string($_POST['cat_name']);
    $parent   = mysql_real_escape_string($_POST['parent']);
    $grp      = mysql_real_escape_string($_POST['grp']);

    // See if that product name is an identical match to another product in the system
    $sql          = mysql_query("SELECT id FROM categories WHERE cat_name='$cat_name' LIMIT 1");
    $productMatch = mysql_num_rows($sql); // count the output amount

    if ($productMatch > 0) 
    {
        echo 'Sorry you tried to place a duplicate "Category" into the system, <a href="category_add.php">click here</a>';
        exit();
    }

    // Add this product into the database now
    $sql2    = mysql_query("INSERT INTO categories (cat_name,parent,group) VALUES('$cat_name','$parent','$grp')") or die (mysql_error());
    $cid     = mysql_insert_id();
    $newname = "$cid.jpg";
    move_uploaded_file( $_FILES['fileField']['tmp_name'], "../cat_images/$newname");
    header("location: category_add.php"); 
    exit();
4

1 回答 1

3

使用这个查询,group是mysql中的保留字。您必须附加`列名。

$sql2 = mysql_query("INSERT INTO categories (`cat_name`,`parent`,`group`) VALUES('$cat_name','$parent','$grp')") or die (mysql_error());
于 2013-02-21T07:31:01.723 回答