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

后端 未结 7 578
礼貌的吻别
礼貌的吻别 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:50

    Always at least use mysql_real_escape_string when adding user-provided values into the Database. You should look into binding parameters or mysqli so your query would become:

    INSERT INTO `table` (`row1`) VALUES (?)
    

    And ? would be replaced by the actual value after sanitizing the input.

    In your case use:

    $result = mysql_query("INSERT INTO `table` (`row1`) VALUES ('".mysql_real_escape_string($_POST['text'])."') ") or die(mysql_error());
    

    Read up on SQL Injection. It's worth doing right ASAP!

提交回复
热议问题