Hi,
I am trying to security protect my database. I have javascript validation on the html form, but I am aware that this can be disabled so want to check the insert page is suitably protected.
Firstly: Am I right in think real_escape_string is sufficient protection, or do I need to validate and sanitize as well?
Secondly: Have I applied it correctly below, I think I can write it as per below to check multiple fields, but I'm not certain I interpretted this correctly.
Thirdly: I am getting mysql error on this page, I can not work out what I am doing wrong, any pointers?
Any help would be much appreciated.
<html>
<head>
</head>
<body>
<?php
function check_input($value)
{
if (get_magic_quotes_gpc())
{
$value=stripslashes($value);
}
if (!is_numeric($value))
{
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}
$con = mysql_connect("localhost","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$sql="INSERT INTO table(fname, lname, email, cemail, pword, cpword, sex, DOBMonth, DOBDay, DOBYear, natcountry, rcountry, postcode, industry, other, date)
VALUES
('$_POST[fname]','$_POST[lname]','$_POST[email]','$_POST[cemail]','$_POST[pword]','$_POST[cpword]','$_POST[sex]','$_POST[DoBMonth]','$_POST[DOBDay]','$_POST[DoBYear]','$_POST[sex]','$_POST[ncountry]','$_POST[postcode]','$_POST[industry]','$_POST[other]','$_GET[CURDATE]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error);
}
mysql_close($con);
?>
</body>
</html>