我使用unity將值傳遞給我的PHP腳本與HTTP GET。我是新來的PHP,只是讓我的腳本工作,但是,我想確保我可以防止SQL注入。有人可以看看這個,讓我知道我需要改變以保護它嗎?PHP + SQL腳本 - 防止SQL注入
<?php
$servername = "localhost";
$username = "Test";
$password = "Test";
$dbname = "Test";
$userId = $_GET['userId'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT rp FROM RP where userID = '$userId'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
//echo "UserID: " . $row["userID"]. " - RP: " . $row["rp"]."<br>";
echo "RP: " . $row["rp"]."<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1 –
不要使用'query('use' prepare''' execute '並且將值傳遞給執行請參見上面的鏈接^ – chris85