dongyuan1970 2013-09-25 03: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 03: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部