0

I'm working on a website with PHP and I have an error in my code that I don't know how to solve.

The error is :

( ! ) Warning: Invalid argument supplied for foreach() in C:\wamp64\www\npanel\reload_userlist.php on line 13

And my code is :

$selectionuser = $db->query("SELECT * FROM `users\`");

                    // Print Output
                    foreach($selectionuser as $AfficheUser)
                    {
                     if($_SESSION["id"] == "1"){
                      $buttondelete = "<a href='assets/suser.php?id=" . htmlspecialchars($AfficheUser['id']) . "' class='sidebar-link btn btn-danger'><span class='hide-menu'>Delete</span></a>";
                     }

Can someone help me ? Thanks ! ^^

I'm Using a MySQL database

enter image description here The goal is to get an userlist of people registered on my website. here in my webpage

brombeer
  • 8,716
  • 5
  • 21
  • 27
sorrow
  • 1
  • 2
  • 1
    What does `$db->query()` returns? Because it's not _iterable_ element – Justinas Mar 25 '22 at 10:39
  • have you googled the error? It's telling you that `$selectionuser` isn't a value you can use in a foreach - it's not a list or collection that you can loop through. So you need to check what it actually is (you can use `var_dump($selectionuser);` to check). That's the first step to working out what to do instead. – ADyson Mar 25 '22 at 10:56
  • Maybe $selectionuser is returning empty. Make sure $selectionuser is not returning empty value before itterate. – Hasinur Mar 25 '22 at 11:28
  • is the users\ table named like that really? – Dale Mar 25 '22 at 12:19

0 Answers0