MySQL Query not inserted when PHP variable contains single quotes

后端 未结 7 651
情书的邮戳
情书的邮戳 2021-01-17 05:49

This query not inserted when variable $subject has single quotes . Is there any possible solution available ?

mysql_query(\"INSERT INTO  table  (to_email_id,         


        
7条回答
  •  不要未来只要你来
    2021-01-17 06:42

    Consider using Parameterized Queries using PDO for example.

    Alternately, enclose your variables in brackets { }.

    Edit:

    I missed that your variable $subject contains single quotes. This means you have to escape them. (See the myriad of other answers and mysql_real_escape_string() about this.) But as you can see, single quotes inside the variable is exactly how injection attacks work. Escaping them helps prevent such problems as well as allow your query to store the expected data.

    No answer about injection attacks is complete without referencing Bobby Tables.

提交回复
热议问题