RE: mysql_num_rows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Craig,

First off, where is the $db variable being set? You include it in:

$result = mysql_query($query, $db);

which is line 65, but, according to your function, it's not passed into the
function as an argument and I don't see you setting $db equal to anything
inside the function.

Second, why are you checking

if(!$query)?

You set $query to the string

$query ="SELECT username FROM users WHERE username=('$username')";

so why would it never NOT be set? Maybe you mean to check to see if the
query produced any results? In which case you should probably be checking

if(!$results).

Additionally, you should probably add an or die(mysql_error()) after your
mysql_query... line to display errors from the database.

And if your query process fails at line 65 because $db isn't defined, then
line 70 won't work because you haven't performed a query to return any rows.

Hope this helps.

Rich

> -----Original Message-----
> From: Craig Hoffman [mailto:choffman@xxxxxxxxxxx]
> Sent: Wednesday, March 03, 2004 3:34 PM
> To: php-db@xxxxxxxxxxxxx
> Subject: Re:  mysql_num_rows
> 
> 
> ok, I uncommented the line and changed a few things around.  
> However I  
> am still getting errors.   I really do appreciate everyone's  help.   
> Thanks CH
> Here is the 'new' code:
> 
> function notify_password($username, $password)
> // notify the user that their password has been changed
> {
> 
>     $query ="SELECT username FROM users WHERE username=('$username')";
> => line 65 	$result = mysql_query($query, $db);
>      if (!$query)
>      {
>        return false;  // not changed
>      }
> => line 70 	else if (mysql_num_rows($result)==1)
> 
>        $user_id = mysql_result($result, 0, 'user_id');
>        $from = "From: missy@xxxxxxxxxxxxxxxx \r\n";
>        $mesg = "Your password has been changed to $password \r\n"
>                ."You might want to change it next time you 
> log in. \r\n";
> 
>        if (mail($username, 'Cyclists Edge login information', $mesg,  
> $from))
>          return true;
>        else
>          return false;
>      }
> 
> 
> Warning: mysql_query(): supplied argument is not a valid MySQL-Link  
> resource in  
> /Users/choffman/Sites/www/cyclistsedge/include/ 
> forgot_password_functions.php on line 65
> 
> Warning: mysql_num_rows(): supplied argument is not a valid MySQL  
> result resource in  
> /Users/choffman/Sites/www/cyclistsedge/include/ 
> forgot_password_functions.php on line 70
>   Your new password has been sent to your email address.
> 
> __________________________________
> Craig Hoffman - eClimb Media
> 
> v: (847) 644 - 8914
> f: (847) 866 - 1946
> e: choffman@xxxxxxxxxx
> w: www.eclimb.net
> _________________________________
> On Mar 3, 2004, at 2:17 PM, Daniel Clark wrote:
> 
> >>      $query ="SELECT username FROM users WHERE  
> >> username=('$username')";
> >>     // $result = mysql_query($query, $db);
> >
> >
> > Above line should be uncommented.
> >
> >
> >>      if (!$query)
> >
> > And the "if" checking the number of rows returned from the 
> $result set.
> >
> > -- 
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux