I used to make $sql and execute it directly with no control and now I'm swapping to prepared statements, I've made one on my localhost but the moment I tried it on a live server. This is what it used to look like before
<?php
$sql = "SELECT * FROM tbl_front WHERE active='Yes'";
$res = mysqli_query($conn, $sql);
if($res==TRUE)
{
$count = mysqli_num_rows($res);
if($count>0)
{
while($row=mysqli_fetch_assoc($res))
{
$day1=$row['day1'];
$day2=$row['day2'];
$time1=$row['time1'];
$time2=$row['time2'];
echo "
<h2 class='hours'>RADNO VRIJEME:</h2>
<h2 class='hours'>$day1 - $day2 <br>$time1:00 - $time2:00</h2>";
}}
else
{
echo "
<h2 class='hours'>Privremeno zatvoreno</h2>";
}}
?>
Works perfect, and now I've changed it to this
$sql = "SELECT * FROM tbl_front WHERE active=?";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)){
echo 'lol';
}
else{
mysqli_stmt_bind_param($stmt, "s", "Yes");
mysqli_stmt_execute($stmt);
$res = mysqli_stmt_get_result($stmt);
$count = mysqli_num_rows($res);
if($count>0)
{
while($row=mysqli_fetch_assoc($res))
{
$day1=$row['day1'];
$day2=$row['day2'];
$time1=$row['time1'];
$time2=$row['time2'];
echo "
<h2 class='hours'>RADNO VRIJEME:</h2>
<h2 class='hours'>$day1 - $day2 <br>$time1:00 - $time2:00</h2>";
}}
else
{
echo "
<h2 class='hours'>Trenutno zatvoreno</h2>";
}}
?>
I don't get crashes but I can't get output, I tried without the $count or changing it to $count=mysqli_stmt_num_rows($res); but i simply can't draw data out of the database, not even with print_r($res); Any ideas on how I might be able to solve this?