Jump to content

Parameters for Protection:SQL Injection


Spunky

Recommended Posts

Based on my reading here: http://www.w3schools.com/sql/sql_injection.asp

 

I attempted to change:

$query= "INSERT INTO houses (location) VALUES ('$location)";mysql_query($query) or die(mysql_error());

(which works) into this:

$query= $dbh->prepare("INSERT INTO houses (location) VALUES (:loc)");$query->bindParam(':loc', $location);$query->execute();mysql_query($query) or die(mysql_error());

The code doesn't work. I am not sure if I translated correctly how to add "parameters" to the code to protect against SQL injection.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...