代码之家  ›  专栏  ›  技术社区  ›  dennis

PHP检查会话(如果有特权)

  •  0
  • dennis  · 技术社区  · 9 年前

    我正在使用MySQL查询在数据库中创建一个产品,但我遇到了一个错误:

    您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,在第1行的“desc,fprice,inkoop,image,author,html”附近使用正确的语法

    我在谷歌上搜索了一下,但在我的代码中找不到任何问题:

    <?php
    
    if(isset($_POST['submit'])) {
        $shopid1 = $_POST['productid'];
        $prodname1 = $_POST['productname'];
        $desc1 = $_POST['desc'];
        $fprice1 = $_POST['fprice'];
        $price1 = $_POST['price'];
        $inkoop1 = $_POST['inkoop'];
        $image1 = $_POST['image'];
        $qty1 = $_POST['qty'];
        $html1 = $_POST['html'];
        $author1 = $_SESSION['name'];
    
    
    
            mysql_query("INSERT INTO products(shopid, name, qty, price, desc, fprice, inkoop, image, author, html) VALUES('$shopid1', '$prodname1', '$qty1', '$price1', '$desc1', '$fprice1', '$inkoop1', '$image1', '$author1', '$html1')", $conn)
                or die(mysql_error());  
            Header("Location: products.php");
    
    } else {
    
    }
    
    
    ?>
    

    希望有人能诊断我的问题!谢谢

    3 回复  |  直到 9 年前
        1
  •  1
  •   Sougata Bose    9 年前

    desc 是保留关键字。试试看-

    INSERT INTO products(shopid, name, qty, price, `desc`,.....
    

    或者相应地重命名它。

        2
  •  0
  •   AnkiiG    9 年前

    desc 是一个关键字,可以使用反引号或在数据库中重命名(如果可能)。尝试如下:

    INSERT INTO products
    (shopid, name, qty, price, `desc`, fprice, inkoop, image, author, html)
    VALUES
    ('$shopid1', '$prodname1', '$qty1', '$price1', '$desc1', '$fprice1', '$inkoop1', '$image1', '$author1', '$html1')
    
        3
  •  0
  •   Little Phild    9 年前

    尝试逃离 keyword (描述) 在您的查询中

        <?php
    
    if(isset($_POST['submit'])) {
        $shopid1 = $_POST['productid'];
        $prodname1 = $_POST['productname'];
        $desc1 = $_POST['desc'];
        $fprice1 = $_POST['fprice'];
        $price1 = $_POST['price'];
        $inkoop1 = $_POST['inkoop'];
        $image1 = $_POST['image'];
        $qty1 = $_POST['qty'];
        $html1 = $_POST['html'];
        $author1 = $_SESSION['name'];
    
    
    
            mysql_query("INSERT INTO products(shopid, name, qty, price, `desc`, fprice, inkoop, image, author, html) VALUES('$shopid1', '$prodname1', '$qty1', '$price1', '$desc1', '$fprice1', '$inkoop1', '$image1', '$author1', '$html1')", $conn)
                or die(mysql_error());  
            Header("Location: products.php");
    
    } else {
    
    }
    
    
    ?>
    

    你也可以签出保留的关键字,这样下次就不会再犯错误了 MYSQL Reserved Keyword

    推荐文章