I am quite new to PHP and have been told my MySQL statements are insecure from injections.
There are my old queries:
$addbook = "INSERT INTO bookings (bookID, startDate, startTime, endDate, endTime) ";
$addtempres .= "VALUES ('".$bookid."', '".$startdate."', '".$starttime."', '".$enddate."', '".$endtime."')";
$insertBook = mysql_query($addbook);
$getblogposts = mysql_query("SELECT * FROM blogposts WHERE deleted = 'no' ORDER BY postID DESC LIMIT 4");
After reading about it I understand they are insecure, I also understand that mysql_query is old, and being depreciated.
I have however written a lot of these queries and the realization that they are all old and unsafe is daunting, so I started trying to secure them.
So I did this:
$escapedbookid = mysql_real_escape_string($bookid) ;
$escapedstartdate = mysql_real_escape_string($sqlcoldate);
$escapedstarttime = mysql_real_escape_string($forstarttime);
$escapedenddate = mysql_real_escape_string($sqlretdate);
$escapedendtime = mysql_real_escape_string($forendtime);
$escapedactive = mysql_real_escape_string('false');
$addtembook = "INSERT INTO bookings (bookID, startDate, startTime, endDate, endTime) ";
$addtempres .= "VALUES ('".$escapedbookid."', '".$escapedstartdate."', '".$escapedstarttime."', '".$escapedenddate."', '".$escapedendtime."')";
$insertRes = mysql_query($addtempbook);
Is this more secure? I appreciated PDO prepared statements are easier and more secure when I learn to translate my current queries into them, but I was just wondering if what I am doing is making things more secure or not?