Link to home
Start Free TrialLog in
Avatar of CiscoTavon
CiscoTavon

asked on

check username. password, user status, set cookie using PHP & MySQL

what is the php code to do the following

take username password from webpage

each person in the users table has a username, password, admin field and useryet field.  the admin and useryet fields are either 0 or 1

if username and password match and someone is an admin (admin field =1) I need to create an admin cookie and go back to the homepage
if username and password match and someone is a user(useryet =1) I need to create an user cookie and go back to the homepage

if username and password match and someone is a user but not an approved member yet (useryet=0) then display a sorry you are not an approved member yet message

if username password don't match display unknown user message
Avatar of rajkumar_pb
rajkumar_pb
Flag of India image

I used the below code and to be frank its more than good enough of what you asked for.

http://www.evolt.org/node/60384

Also try this. Simple, and much secure. Easy to configure

http://php-login-script.com/
ASKER CERTIFIED SOLUTION
Avatar of vidularandunu
vidularandunu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CiscoTavon
CiscoTavon

ASKER

Thank you for your help.  I'm still having some problems.  it is failing at the part of code I included in this post

I enter a test username and password.  it just displays "Invalid Username or password 1"

it appears to not be doing a query of the table.

if I go direct to the MySQL database and enter
SELECT * from users WHERE username = "bob";
it returns 1 result as it should


//query the database
$q = "SELECT * from user_table WHERE username = '".$username."' LIMIT 1";
$result = mysql_query($q,$connection);
while($result = mysql_fetch_array($q))
{
      $array [] = $result;
}      

if(!isset($array)){
      echo "Invalid Username or password 1";
}

Open in new window

remove the while loop, and add a single mysql_fetch_array statement, since it is returning a single result..
(make sure you use the correct table name in the php query code)..

also do a print_r on the result and see what you're getting.


$result = mysql_fetch_array($q)
if(!isset($result){ ..}

Open in new window