cozzy1984
03-06-2008, 11:07 AM
Hi there, have done a good few pages for my website in php but have been looking into using mysql_real_escape_string to make it more secure and was just wondering where abouts do i add it.
Is it just simply a matter of adding it when i define my variables and is this enough?
For instance i had on a edit page the varaibles near the top like this:
if (isset($_POST['submit'])) {
$email = trim($_POST['email']);
$forename = trim($_POST['forename']);
$surname = trim($_POST['surname']);
$location = $_POST['location'];
$town = $_POST['town'];
$msn = $_POST['msn'];
$website = $_POST['website'];
$motto = $_POST['motto'];
$bio = $_POST['bio'];
$avatar = $_POST['avatar'];
and have now changed them into this:
if (isset($_POST['submit'])) {
$email = mysql_real_escape_string($_POST['email']);
$forename = mysql_real_escape_string($_POST['forename']);
$surname = mysql_real_escape_string($_POST['surname']);
$location = mysql_real_escape_string($_POST['location']);
$town = mysql_real_escape_string($_POST['town']);
$msn = mysql_real_escape_string($_POST['msn']);
$website = mysql_real_escape_string($_POST['website']);
$motto = mysql_real_escape_string($_POST['motto']);
$bio = mysql_real_escape_string($_POST['bio']);
$avatar = mysql_real_escape_string($_POST['avatar']);
Basically i am just wondering if this is the right way to make it more secure and if i need to be using the mysql_real_escape_string anywhere else, like in my update queries.
Thanks
Aaron
Is it just simply a matter of adding it when i define my variables and is this enough?
For instance i had on a edit page the varaibles near the top like this:
if (isset($_POST['submit'])) {
$email = trim($_POST['email']);
$forename = trim($_POST['forename']);
$surname = trim($_POST['surname']);
$location = $_POST['location'];
$town = $_POST['town'];
$msn = $_POST['msn'];
$website = $_POST['website'];
$motto = $_POST['motto'];
$bio = $_POST['bio'];
$avatar = $_POST['avatar'];
and have now changed them into this:
if (isset($_POST['submit'])) {
$email = mysql_real_escape_string($_POST['email']);
$forename = mysql_real_escape_string($_POST['forename']);
$surname = mysql_real_escape_string($_POST['surname']);
$location = mysql_real_escape_string($_POST['location']);
$town = mysql_real_escape_string($_POST['town']);
$msn = mysql_real_escape_string($_POST['msn']);
$website = mysql_real_escape_string($_POST['website']);
$motto = mysql_real_escape_string($_POST['motto']);
$bio = mysql_real_escape_string($_POST['bio']);
$avatar = mysql_real_escape_string($_POST['avatar']);
Basically i am just wondering if this is the right way to make it more secure and if i need to be using the mysql_real_escape_string anywhere else, like in my update queries.
Thanks
Aaron