On 15-Apr-01 ªüÂ× wrote:
> $result=0;
> $query="select * from users where user_id='$user_id'";
       // why fetch all the fields to test an "exists" ?

> $result=mysql_query($query,$link);
                        // where's the test, in case it failed ?

> if(mysql_fetch_row($result)) $result=1;
                             // ^^^^^^^ you just trashed your result set
> else $result=0;
     //      ditto

> 
> I use the function of "mysql_fetch_row()" in register2.php
> and it's output is the follow list:
> 
> Warning: Supplied argument is not a valid MySQL result resource in
> /home/shin/public_html/register2.php on line 27 
> 

-------

// assumes the $link is valid !?!

function user_exists($user_id) {
    global $link;

    $query="select * from users where user_id='$user_id'";
    $result=mysql_query($query,$link);
    if (! $result)
        die ('<P>' .mysql_errno() .'<BR>'.mysql_error() ."<BR>\n");

    $cnt = mysql_numrows($result);
    return($cnt);
}
        
function user_exists2($user_id) {
    global $link;

    $query="select count(*) as cnt from users where user_id='$user_id'";
    $result=mysql_query($query,$link);
    if (! $result)
        die ('<P>' .mysql_errno() .'<BR>'.mysql_error() ."<BR>\n");

    $row=mysql_fetch_object($result);
    return($row->cnt);
}

 
Regards,
-- 
Don Read                                       [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to