我已經看到了一些使用一種叫做PDO進行查詢從SQL感染,或其他使用real_escape安全的例子,但似乎都不完整或承擔一些知識。所以我問,採取這個簡單的更新查詢,並從SQL注入安全。
function updateUserName($id,$first,$last)
{
$qry = 'UPDATE user SET first = "'.$first.'", last = "'.$last.'" WHERE id = '.$id;
mysql_query($qry) or die(mysql_error());
}
完全重複:http:// stackoverflow。com/questions/60174/best-way-to-stop-sql -injection-in-php – jvenema 2010-02-25 18:41:03