MySQL Query not inserted when PHP variable contains single quotes

后端 未结 7 543
情书的邮戳
情书的邮戳 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:36

    Escape your parameters.

    $to = mysql_real_escape_string($to);
    $subject = mysql_real_escape_string($subject);
    mysql_query("INSERT INTO  table (to_email_id, subject) values('$to', '$subject');");
    

    Manual: mysql_real_escape_string()

    Also, please read about SQL injection attacks.

提交回复
热议问题