I work as a coding school mentor and I am introducing my students to PHP and concepts like PDO and prepared statements. To show them how prepared statements(among other things) can be useful in protecting against SQL injection, I am trying to do some SQL injection of my own on my own form. I have tried tens of variants of a DELETE FROM users
query to no success even though these queries give the intended results when i run them on PHPMyAdmin. This begs the question: did PHP introduce something extra for security against SQL injection recently? Or maybe I am doing something wrong?
Below is the code that I am using to insert a new user:
try {
$sql = "INSERT INTO users (name, email) VALUES ('$name', '$email')";
$this->conn->exec($sql);
echo "New record created successfully";
} catch (PDOException $exception) {
echo $exception;
}
Whenever i try any input like Bob'); DELETE FROM users where ('1' = '1
it gives me
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELETE FROM users where ('1' = '1')' at line 1
Even though the same query works on PHPMyAdmin
Any thoughts?