Form
<FORM method="post" action="for.php">
<input type="text" name="first" placeholder="first"><br>
<input type="text" name="last" placeholder="last">
<input type="submit">
</FORM>
Form Processing
How do I use SQL injection prevention methods when processing the form. I checked this link and I am confused after reading it: How can I prevent SQL injection in PHP?
<?php
$db_username = "sanoj";
$db_password = "123456";
try {
#connection
$conn = new PDO('mysql:host=localhost;dbname=localtest', $db_username, $db_password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$data = $conn->prepare('INSERT INTO test (first, last) VALUES (:first, :last)');
$first = mysql_real_escape_string($_POST['first']);
$last = mysql_real_escape_string($_POST['last']);
$data->execute(array(':first' => $first, ':last' => $last));
#exception handiling
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
Error
When I run the above code am getting this ERROR
Deprecated: mysql_real_escape_string(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\Users\logon\Documents\NetBeansProjects\teste local\for.php on line 11