Login problems

They have: 15 posts

Joined: Jun 2002

Hiya, I'm having a problem with a login script I'm working on. I coded it to look in Mysql for a list of users and passwords, and if a username matched up with a password it would allow access. But I can only get the 1st account to work, not the others.

<?php
If ($op == \"\") {
echo (\"
<HTML>
<TITLE>Login Page</TITLE>
<BODY>
<FONT FACE=arial, helvetica SIZE=2>
<FORM METHOD=post ACTION=login.php?op=login>
<B>Login name:</B><BR>

<INPUT TYPE=text SIZE=30 NAME=loginname><BR>

<B>Password:</B><BR>
<INPUT TYPE=password SIZE=30 NAME=loginpass><BR>
    <input type=submit value=Submit>&nbsp;&nbsp;<input type=reset value=Clear>
    </form>
</BODY>
</HTML>
\");
}

IF (
$op == \"login\") {
   
$result = mysql_query(\"SELECT * FROM {$prefix}user\");
   
$row = mysql_fetch_array($result);
               
$uname = $row[\"name\"];
               
$upass = $row[\"password\"];
               
$email = $row[\"email\"];
       
$uid = $row[\"id\"];

echo mysql_error();   
If ((
$loginname == \"$uname\") && ($loginpass == \"$upass\")) {
        Setcookie(\"login[user]\",
$loginname,time() + 86400);
        Setcookie(\"login[pwd]\",
$loginpass,time() + 86400);
        Setcookie(\"login[email]\",
$email,time() + 86400);
        Echo(\"Logged in. Welcome
$uname. <a href=admin.php>Continue</a>...\");
     }
     If (
$loginname == \"\") {
        Echo(\"No username submitted.\");
     }
     If ((
$loginname == \"$uname\") && ($loginpass != \"upass\")) {
        Echo(\"Password incorrect. Passwords are case sensitive. \");
     }
     If (
$loginname != \"$uname\") {
        Echo(\"No such username. Usernames are case sensitive. \");
     }
echo mysql_error();
}}
?>

Dream until your dreams come true. For those with wings fly to your dreams.

Era Creations: What games were meant to be

He has: 1,380 posts

Joined: Feb 2002

well...i'm not much on the PHP side of stuff, but i do know that values (i.e. "whatever">)
should have quotes

He has: 1,016 posts

Joined: May 2002

Maybe you should add which user's information you'd like to get in your MySQL query? Your current query asks for all users and then you only do one fetch which means you only get the first user's information. Add WHERE name LIKE '$loginname' to the end of your MySQL query. Also use mysql_fetch_assoc($result); instead of mysql_fetch_array().

They have: 15 posts

Joined: Jun 2002

It works. *bows before zollet*

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.