i am converting my code to PDO to make my website less vulnerable
this is my code and according to another post on here this should work:
$stmt = $handler->prepare("SELECT * FROM news ORDER BY date DESC LIMIT 5");
$run = $stmt->execute();
if(!$run){
echo 'sorry';
}
while($row = $query->fetch(PDO::FETCH_ASSOC)){
echo $row['title'];
$article_id = $row['article_id'];
$user_id = $row['user_id'];
$title = $row['title'];
$content = $row['content'];
$date = $row['date'];
$stmt2 = $handler->prepare("SELECT * FROM users WHERE id = :id");
$stmt2->bindParam(':id',$id);
$stmt2->execute();
$row2 = $stmt2->fetch(PDO::FETCH_ASSOC);
$user_name = $row2['username'];
$title2 = str_replace(" ","-",$title);
echo '<div class="row">
<div class="col-lg-12"><h3 class="para"><a class="para" href="http://news.red-sec.net/article/'.$article_id.'/'.$title2.'">'.$title.'</a></h3>
<p class="para">Written by: '.$user_name.'</p>
</div>
i am trying to echo $row['title']; to see if it works but it doesnt echo anything out so i am guessing that there is a mistake somewhere.
EDIT:
It doesn't echo sorry so i know that the statement is being run...