Re: simple mysql_result() question
| From: | Richard Harb | Date: | Thu, 08 Apr 2004 03:10:42 +0000 |
| Subject: | Re: simple mysql_result() question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-182778@lists.php.net to get a copy of this message | ||
Uhm .. I usually do:
SELECT COUNT(id) FROM users WHERE name='$username' AND
password='$password'
if (username is found) // hopefully it's unique
found ya
else
sorry
This way you aleays have a value returned...
HTH
Richard
Thursday, April 8, 2004, 3:29:11 AM, you wrote:
> hello,
> I am trying to authenticate users. I run this MySQL query using
> vars provided via a form....
> select password from dealers where username = '$user'
> this works great if $user is actually a user in the database.
> otherwise i get this error....
> Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 3
> in /var/www/php/AuthTool.php on line 52
> its because of this....
> $thePass = mysql_result($result,'0','password');
> is there a way to stop this error, should i be using mysql_fetch_array
> instead? Code below.
> Thanks,
> jd
> function auth(){
> $user = $_POST['user'];
> $pass = $_POST['pass'];
> $query = "select password from dealers where username = '$user'";
> $result = $this->sqlQuery($query);
> if(!$result){
> echo "Sorry there was a error\n";
> }
> else{
> $thePass = mysql_result($result,'0','password');
> if($thePass){
> echo "$thePass\n";
> }
> else{
> echo "no such user - $user\n";
> }
> }
> }
> --
> jd@taproot.bz
> "Bad spellers of the world untie!"