我的数据库最近遭受了SQL注入攻击,主要是因为我对编程比较新,并且不知道类似的东西。我一直在努力学习如何防止它们,但我无法弄清楚如何使用这个脚本。我确实有成功实现的其他类型的脚本。 如何使用此脚本阻止SQL注入攻击?
<?php
$autor = $_GET["multi"];
$autop = $_GET["multis"];
$sql = "UPDATE autoj SET autob = '$autop' WHERE autoq = '$autor'";
$hd = "something";
$dd = $_GET['something'];
$ud = "something";
$pd = "something";
$mysqli = new mysqli($hd, $ud, $pd, $dd);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$result = $mysqli->query($sql);
if ($result) {
....
答案 0 :(得分:1)
如何使用此脚本阻止SQL注入攻击?
答案 1 :(得分:0)
试试这个:
$hd = "something";
$dd = "PUT SOMETHING HERE";
$ud = "something";
$pd = "something";
$mysqli = new mysqli($hd, $ud, $pd, $dd);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$autor = $_GET["multi"];
$autop = $_GET["multis"];
$autor = $mysqli->real_escape_string($autor);
$autop = $mysqli->real_escape_string($autop);
$sql = "UPDATE autoj SET autob = '$autop' WHERE autoq = '$autor'";
另外,在第二行,我看到您使用$ _GET ['something']来选择数据库。不。
答案 2 :(得分:-1)
使用mysqli_real_escape_string http://php.net/manual/en/mysqli.real-escape-string.php