所以我发现这个形式我刚刚崩溃,甚至没有提交内容直到第一个撇号,当有人在这个文本区域输入撇号时。我如何转义内容,以便将它们放入我的MySQL表中?谢谢!
<form action=\"./functions/notes.php\" method='post'>
<input type='hidden' id='ID' name='ID' value='{$row['ID']}' />
<textarea placeholder=\"Add more notes here...\" name=\"notes\"></textarea><br />
<input type='submit' name='formNotes' id='formNotes' value='Add to Notes' />
</form>
然后在notes.php文件中
$notesID = $_POST['ID'];
$note = $_POST['notes'];
$date= date('Y-m-d');
$result = mysql_query("UPDATE Project_Submissions SET Notes=CONCAT(Notes,'<br />".$date." ".$note."') WHERE ID ='".$notesID."'");
答案 0 :(得分:1)
撇号对SQL具有特殊意义,因此为了使它们进入数据,它们需要被转义&#34; PHP有一个快速的功能,它还进行一些安全检查,以帮助防止您的数据库被黑客入侵。
$note = mysql_real_escape_string($note);
DITTO从远离mysql转移到mysqlI
使用MySQLI,它只需要提供连接变量....
$note = mysqli_real_escape_string($link, $note);