I have a webpage that allows 3 users to login and vote, at the login page it displays the 3 users however ive to change the following code so that at the login page it will only display the users who haven't voted yet. What do i need to change in the loop?

<?php

  // change this loop to only display those users who have not yet voted
  echo "<p><span class=\"bold\">Users available:</span><br />";
  foreach ($users as $user=>$password) {
   if (!isset($_SESSION["$users"]))
  {
     // test to see if a user has already voted before echo-ing to screen
     // by checking if the value of $_SESSION["user"] is equal to "voted" (1a)
     echo "$user ";
  }   
  echo "</p>";
}
  $message="";

  if (isset($_GET["failCode"]) && $_GET["failCode"]==1) {
     $message="<p><span class=\"loginMessage\">".
              "Bad username entered</span></p>";
  }

  if (isset($_GET["failCode"]) && $_GET["failCode"]==2) {
     $message="<p><span class=\"loginMessage\">".
              "Wrong password entered</span></p>";
  }

  echo "$message";
?>

Where is the code getting the 'voted' from the database and storing it in the session?

there's other files that i have, but i don't really understand php that much so wasnt sure what other parts to put up.

we'd need the file that has the database functions in order to create a loop the way you wanted it.
right now, it just echoes everything it can find, but the loop should be modified by inserting an IF, which uses the database to see if a certain user has already voted.

so right now, your loop is like this:
user1 -> echo user1
user2 -> echo user2
etc.

and you'll need

user1 -> check in the database if the user has already voted, and if not -> echo user1

do you have any files named database.php, or db.php or anything in that sense?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.