I would like to know the definitive way to guard against sql injection attacks so that I can incorporate these protections into my code, but I am a bit unsure as to which are the best commands to use. Do you have to use them all, or is one sufficient? I've never had a complete grasp of what "escaping" means, so could someone please illustrate the best way to safely add data to a database? I've seen things like below, which would imply that you could thereafter refer to the variable as $var, but I have found this not to be the case:
Do you add data like this?...Code:$var = mysql_real_escape_string($_POST['var']); $var = htmlspecialchars($_POST['var']);
or like this?...Code:INSERT INTO location ( location, address, city) VALUES ( '" .$_POST['location']."', '".$_POST['address']."', '".$_POST['city']."' )";
or what???Code:$location = mysql_real_escape_string($_POST['location']); $address = htmlspecialchars($_POST['address']); $city = mysql_real_escape_string($_POST['city']); VALUES ( '" .$location."', '".$address."', '".$city."' )";
Thanks.



Reply With Quote





Bookmarks