I am currently using mysql_real_escape_string()
but have heard of people using "Prepared Statements". So I would like to know if this way mysql_real_escape_string()
is still safe, but if it isn't, could somebody explain how I could change my code to allow Prepared Statements?
$conn=mysql_connect("localhost", "u611142741_list", "REDACTED");
mysql_select_db("u611142741_sugge", $conn);
// If the form has been submitted
if (trim($_POST["suggestion543"]) == "") {
echo "Error";
echo '<script language="javascript">';
echo 'alert("Invalid entry! Try Again.")';
echo '</script>';
echo '<script>';
echo 'setTimeout(function(){ window.location="" }, 500)';
echo '</script>';
} else {
$suggestion = mysql_real_escape_string($_POST['suggestion543']);
$ip = $_SERVER['REMOTE_ADDR'];
echo "Thank you for submitting your suggestion!";
echo '<script>';
echo 'setTimeout(function(){ window.location="" }, 2000)';
echo '</script>';
};
// Build an sql statment to add the student details
$sql="INSERT INTO suggestions
(`Suggestion`, `IP Address`) VALUES
('$suggestion','$ip')";
$result = mysql_query($sql,$conn);
// close connection
mysql_close($conn);