I have the following code and I need to know if this is an unsafe code and if so, how can I make it safe.
I know that I can convert it to Prepared statements
but I need to know (for my own knowledge) if it is possible to make this code safe without using prepared statements?
This is the code:
$sql="SELECT `id`, `title`, `slug`, `comment`, `date_added` FROM `blogs` WHERE slug='$title'";
$query = mysqli_query($db_conx, $sql);
$existCount = mysqli_num_rows($query);
if ($existCount!=0) {
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
$id = $row["id"];
}
}
Any advice would be appreciated.
Thanks in advance.