I am designing a simple form that will be used only be me on a password protected web page. However, I have been told I should still design my form to prevent SQL injection attacks. Since I knew nothing about PHP until only a few days ago, I feel less than confident I've followed the tutorials correctly. Is the following code still vulnerable?
<html>
<body>
<form action="gobacktopage.com">
<input type="submit" value="Add Another" />
</form>
</body>
</html>
<?php
$servername = "myserver.amazonaws.com";
$username = "myusername";
$password = "mypassword";
$dbname = "desireddatabase";
$verse= $_POST['verse'];
$book= $_POST['book'];
$reference = $_POST['reference'];
$cleanverse = addslashes($verse);
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($stmt = $conn->prepare("INSERT INTO myverses (versetext, book, reference) VALUES (?, ?, ?)")) {
// Bind the variables to the parameter as strings.
$stmt->bind_param("sss", $cleanverse, $book, $reference);
// Execute the statement.
$stmt->execute();
// Close the prepared statement.
$stmt->close();
}
$conn->close();
?>