dongyuan1970 2013-09-25 11:30
浏览 55
已采纳

MY SQL插入语法错误

I know what a syntax error is but i cant find the problem in my syntax. I did the sql in phpmyadmin first and not ive just copied and put variables in.

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 's new carving chisels. 1 x 13mm 4-point finishing claw Chisel. Southern St' at line 3

Code:

public function insert_row($vendor, $product_link, $product_title, $product_desc, $product_price){
    mysql_query("INSERT INTO `crawl_products` ( `vendor` , `product_link` , `product_title` , `product_desc` , `product_price` )
        VALUES (
        '$vendor', '$product_link', '$product_title', '$product_desc', '$product_price'
        )") or die(mysql_error());
}

Many Thanks.

  • 写回答

3条回答 默认 最新

  • downloadbooks_2014 2013-09-25 11:36
    关注

    You need to apply mysql_real_escape_string over each variable before running the insert query

    public function insert_row($vendor, $product_link, $product_title, $product_desc, $product_price){
    
        $vendor = mysql_real_escape_string($vendor);
        $product_link = mysql_real_escape_string($product_link);
        $product_title = mysql_real_escape_string($product_title);
        $product_desc = mysql_real_escape_string($product_desc);
        $product_price = mysql_real_escape_string($product_price);
    
        mysql_query("INSERT INTO `crawl_products` ( `vendor` , `product_link` , `product_title` , `product_desc` , `product_price` )
            VALUES (
            '$vendor', '$product_link', '$product_title', '$product_desc', '$product_price'
            )") or die(mysql_error());
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?