0
$query = $db->query("SELECT * FROM recipes WHERE username='".$_SESSION['username']."'");

<h1>my recipes</h1>     
<?php
while ($row = $query->fetch_assoc()) {              
print "<p><a href='../table/show_recipe.php?id=".$row['id']."'>".$row['name']."</a></p>";
}       
?>

Which command should be added if there are no user recipes yet?

Will the message "No recipes currently exist" be printed?

jarlh
  • 42,561
  • 8
  • 45
  • 63
  • show us what have you done so far – ahmednawazbutt Dec 05 '19 at 12:52
  • 4
    Hi, welcome to stackoverflow. Your code is vulnerable to [SQL Injection](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). You should always bind your parameters when dealing with SQL request. – Nicolas Dec 05 '19 at 12:53

1 Answers1

0

Make the recipe column "Null" by default.

ALTER TABLE `recipes` CHANGE COLUMN `recipe_column_name` DEFAULT 'NULL' ;

And execute the following query.

"SELECT *, ifnull(`recipe_column_name`,'No recipes currently exist') as `recep` FROM recipes WHERE username='".$_SESSION['username']."'"

So whenever any row is null in recipe column it will show the message which you have provided. Also you can use aliasing for that complete function.

Udit
  • 129
  • 2
  • 6