0
我有兩個問題SQL注入檢查和PHP拋出錯誤
是下面的代碼(它似乎插入方法工作OK)執業針對SQL注入
如何的好方法會在發生在完整的例子此錯誤消息:
if (!mysqli_query($query,$link)) { die('Error: ' . mysqli_error()); }
這裏是完整的例子:
<?php
$link = mysqli_connect("localhost","root","", "runtracker");
if (!$link)
{
die('Could not connect: ' . mysqli_error());
}
$query="INSERT INTO userinfo (UserName) VALUES (?)";
if ($stmt = mysqli_prepare($link, $query)) {
// Lets create the variables
$name = $_POST['UserName'];
// Bind the variables and execute the query
mysqli_stmt_bind_param($stmt,"s", $name);
mysqli_stmt_execute($stmt);
// And now we close the statement
mysqli_stmt_close($stmt);
}
echo "1 record added";
mysqli_close($link);
?>
哪裏,就是這樣,你做任何事情,以保護自己免受SQL注入? – 2012-12-09 17:46:45
@JackManey,他正在使用準備好的聲明。 – Charles