mardi 31 mars 2015

Else does not work in prepared selection of $row

I want to check if user has set his gender. If not, it will display the 1st echo. If yes, it'll display the echo of his gender. Problem is that the page shows only the 1st echo even though there IS set gender in database... I really don't know why it is not working... My code:



<?php


$username = $_SESSION['username'];

$sql = "
SELECT gender FROM members WHERE username = ?";
$stmt->bind_param('s', $username);

$stmt->execute();
$stmt->bind_result($username);
while ($stmt->fetch()){
if($row['gender'] == ""){
echo "You have not selected your gender yet."; // This is the 1st echo and this is the only one that is displayed
} else {
echo "You selected that you are {$row['gender']}."; // This is not displayed no matter what...
}
}
?>


What I have wrong? *Sorry for wrong title


Aucun commentaire:

Enregistrer un commentaire