dimanche 24 juillet 2016

PHP: if-else statement and mysql_num_rows not working

I'm working on a web page where a user will be allowed to add or edit a feedback for a place. If the person already gave the place a feedback, he/she will be shown an Edit Review button otherwise, the user will be shown an Add Review button.

In my feedback table in my database, I have a places_id and users_id column. Here's my query in PHP (Assuming that $id and $places_id have values):

<?php
$query5 = mysql_query("SELECT * FROM feedback WHERE user_id = '$id' AND places_id = '$places_id'");
$row5 = mysql_fetch_array($query5);

    if($row5['user_id'] != $id){ 
?>

    <a href="trip-advisor.php"><button type="button" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> Back</button></a>
    <button class="btn btn-primary" type="submit" name="submit">Review</button>

    <?php }else{ ?>

    <a href="trip-advisor.php"><button type="button" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> Back</button></a>
    <button class="btn btn-primary" type="submit" name="submit">Edit Review</button>

<?php } ?>

I was thinking that if the query did not return a result where the given user_id is not equal to the user_id in the result, it would let me do my if-else condition. However if there is a feedback for a current place, it displays the button found in the else statement.

What do you think is the problem and why is the if condition not working?

I also tried if(mysql_num_rows($query5)==0) but it's also not working.

Aucun commentaire:

Enregistrer un commentaire