vcherubini
Programmer
Hello:
I am in the process of writing a message board and I have a question about my login script.
Here is the code, or at least the main jist of it:
[tt]
$dbname = "forum";
$dbhost = "localhost";
$dbuser = "user";
$dbpass = "password";
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(!$conn) {
print "failed connection to database: $dbname because of the following reason(s):<br>\n";
print mysql_error();
} else {
$user = "SELECT userid FROM users";
$pass = "SELECT userpass FROM users";
$getvalues = mysql("forum","$user"
;
$numvalues = mysql_numrows($getvalues);
$getval = mysql("forum","$pass"
;
$numval = mysql_numrows($getval);
$i=1;
while ($i<$numvalues) {
$usernames[$i] = mysql_result($getvalues,$i,"userid"
;
$userpasswords[$i] = mysql_result($getval,$i,"userpass"
;
if (($userid == $usernames[$i]) && ($userpass == $userpasswords[$i])) {
print "<br>both username and password are accepted.<br>\n";
print "you are allowed to enter\n";
$go=$userpasswords[$i];
print "<br><a href=\"main.php?go=$go?userpass=$userpasswords[$i]\">click here to continue</a>\n";
break;
} else {
print "<br>your username and password are both incorrect.<br>\n";
print "go back and try again.\n";
$go=0;
break;
}
$i++;
//break;
}
}
?>
[/tt]
If I have only one entry for the users section of my database, it works fine. But when I add another user, it screws up.
I understand how it screws up. It will go through the loop once for the second user and find that the user is not there, printing out that the user is not there, but then it will go through the loop again, this time the variable incremented one, and find that the user exists, therefore printing that he does.
How can I make this loop so that it does not run in a linear fashion?
Any help on how to make a simple login script is appreciated.
Thanks
-Vic
vic cherubini
malice365@hotmail.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
Wants to Know: Java, Cold Fusion, Tcl/TK
====
I am in the process of writing a message board and I have a question about my login script.
Here is the code, or at least the main jist of it:
[tt]
$dbname = "forum";
$dbhost = "localhost";
$dbuser = "user";
$dbpass = "password";
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(!$conn) {
print "failed connection to database: $dbname because of the following reason(s):<br>\n";
print mysql_error();
} else {
$user = "SELECT userid FROM users";
$pass = "SELECT userpass FROM users";
$getvalues = mysql("forum","$user"
$numvalues = mysql_numrows($getvalues);
$getval = mysql("forum","$pass"
$numval = mysql_numrows($getval);
$i=1;
while ($i<$numvalues) {
$usernames[$i] = mysql_result($getvalues,$i,"userid"
$userpasswords[$i] = mysql_result($getval,$i,"userpass"
if (($userid == $usernames[$i]) && ($userpass == $userpasswords[$i])) {
print "<br>both username and password are accepted.<br>\n";
print "you are allowed to enter\n";
$go=$userpasswords[$i];
print "<br><a href=\"main.php?go=$go?userpass=$userpasswords[$i]\">click here to continue</a>\n";
break;
} else {
print "<br>your username and password are both incorrect.<br>\n";
print "go back and try again.\n";
$go=0;
break;
}
$i++;
//break;
}
}
?>
[/tt]
If I have only one entry for the users section of my database, it works fine. But when I add another user, it screws up.
I understand how it screws up. It will go through the loop once for the second user and find that the user is not there, printing out that the user is not there, but then it will go through the loop again, this time the variable incremented one, and find that the user exists, therefore printing that he does.
How can I make this loop so that it does not run in a linear fashion?
Any help on how to make a simple login script is appreciated.
Thanks
-Vic
vic cherubini
malice365@hotmail.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
Wants to Know: Java, Cold Fusion, Tcl/TK
====