I currently use mysql_real_escape_string
to escape a variable when querying the database to prevent SQL injection. For example,
$keyword = mysql_real_escape_string($keyword);
$guideline = mysql_real_escape_string($guideline);
mysql_query("INSERT INTO table1 VALUES('$keyword','$guideline')");
$get = mysql_query("SELECT * FROM table2 WHERE keyword='$keyword'");
while($row = mysql_fetch_assoc($get)) {
//code
}
After reading about SQL injection prevention, i've read this isn't enough to stop SQL injection(so much code to go over now and correct) and i should be using PDO prepared statements? Can i have an example of how to do PDO prepared statements with the same $variables above?