0

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";
?>
3
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by phoenix_2000
0

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.

0

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.