drtkyykai004574380 2014-11-20 18:47
浏览 28
已采纳

PHP插入MYSQL'和“语法错误

So, I am trying to insert into an mysql table a value of a variable. The variable contains both ' and " special characters, so when these occur, it gives a syntax error as it sees it as double ''. Any ideas how I can get around this? I have tried both '' and \" \" variations.

$sql = "INSERT INTO BBC (title, link, description, date)
    VALUES (\"$value\", \"$link1[$c]\", '$description1[$c]', \"$date[$c]\")";
  • 写回答

3条回答 默认 最新

  • drygauost253590142 2014-11-20 19:02
    关注

    test this

     $mysqli = new mysqli("localhost", "my_user", "my_password", "world");
        $value = $mysqli->real_escape_string($value);
        $link1[$c] = $mysqli->real_escape_string(link1[$c]);
        $description1[$c]= $mysqli->real_escape_string($description1[$c]);
        $date[$c]= $mysqli->real_escape_string($date[$c]);
    
        $sql = "INSERT INTO BBC (title, link, description, date)
           VALUES 
          ('$value', '$link1[$c]', '$description1[$c]', '$date[$c]')";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题