PDA

View Full Version : php/mysql authentication


jbroder
01-09-2000, 10:40 PM
I made a signup table in mysql with userid and password fields.

When a user comes back, I want to ask for the userid and password and send the authenticated user to the user's folder.

When the login fails, I want to throw up a failure page.

Here is the php I wrote to do this:

if ($result) {

// get a handle on the failed condition
if (!mysql_result($result,0,"usernum")){
echo "Bad Login";
die;
}
// send to user's directory
$homer =[nbsp][nbsp]mysql_result($result,0,"usernum");
Header( "Location:http://www.guitarwar.com/users/$homer");

}

This works for an authentic signon. It send the user to the correct directory. But when the password/id combination fails, I get this php error:

Unable to jump to row 0 on MySQL result index 2 in /big/dom/xguitarwar/www/login.php on line 25

I would like to surpress that error and throw up my own error message. Any suggestions?

Jon

Justin
01-10-2000, 12:47 AM
That's because there are no results... When the query returns true (eg, if($result) == true) that does not mean it found anything - it simply means that the query was successful, even if no rows were returned.

You should check mysql_numrows($result) first to see if any rows were returned. For example:
</font><font face="Courier" size="3">
if (!$result) {
[nbsp][nbsp] echo &quot;Bad Login&quot;;
[nbsp][nbsp] exit;

}

if (!mysql_numrows ($result)) {
[nbsp][nbsp] echo &quot;Bad Login&quot;;
[nbsp][nbsp] exit;

}

if (mysql_result ($result, 0, username) != $username) {
[nbsp][nbsp] echo &quot;Bad Login&quot;;
[nbsp][nbsp] exit;

}

if (mysql_result ($result, 0, password))...
</font><font face="Verdana, Arial" size="2">
And so on, until they have passed all requirements.

Hope this helps.

------------------
Justin Nelson
FutureQuest Support

jbroder
01-11-2000, 03:38 AM
works like a charm. thanks!