vendredi 23 janvier 2015

php doesn't pass through any of the if statement and goes directly to the else statement

can someone tell me please whats wrong with this, i think i got everything right but my return value pops out everything which is my command for the last else command the if statements doesn't seem to work...



<?php
$con=mysqli_connect("localhost","root","password","dishcover_database");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$images = array();
if(isset($_GET['mydata']) )
$mydata = $_GET['mydata'];
if(isset($_GET['category']) )
$category = $_GET['category'];

if($category == 'Users'){
$result = mysqli_query($con,"SELECT id, dish_name, dish_image, user_username FROM recipes WHERE user_username = '$mydata'");
}else if ($category == 'Recipes'){
$result = mysqli_query($con,"SELECT id, dish_name, dish_image, user_username FROM recipes WHERE dish_name = '$mydata'");
}else if ($category == 'Ingredients'){
$result = mysqli_query($con,"SELECT id, dish_name, dish_image, user_username FROM recipes WHERE user_username = '$mydata'");
}else{
$result = mysqli_query($con,"SELECT id, dish_name, dish_image, user_username FROM recipes");
}
while($row = mysqli_fetch_assoc($result)){
$images[] = $row;
}

echo "{images:".json_encode($images)."}";
mysqli_close($con);
?>

Aucun commentaire:

Enregistrer un commentaire