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条)

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件