Mysql + php with special characters like '(Apostrophe) and " (Quotation mark)

后端 未结 7 584
礼貌的吻别
礼貌的吻别 2020-12-10 05:28

I have been struggling with a small problem for a while. It\'s been there for years but it\'s just been an irritating problem and not a serious one, and I have just worked a

7条回答
  •  清歌不尽
    2020-12-10 05:46

    Your sql string will be:

    INSERT INTO `table` (`row1`) VALUES ('google's site')
    

    Which is not a valid statement. As Nanne wrote, escape the string at least with mysql_real_escape_string : http://php.net/manual/en/function.mysql-real-escape-string.php

    And read about sql injection http://en.wikipedia.org/wiki/SQL_injection

    Think a bit: if someone posts this: $_POST['text'] with value: ');delete from table;....

    Your can say good bye to your data :)

    Always filter/escape input!

    EDIT: As of PHP 5.5.0 mysql_real_escape_string and the mysql extension are deprecated. Please use mysqli extension and mysqli::escape_string function instead

提交回复
热议问题