error using mysql_num_rows( )

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fish44

    error using mysql_num_rows( )

    Ive got the following code which works great on my localserver, but
    when i upload it to my service provider i get an error

    "Warning: mysql_num_rows( ): supplied argument is not a valid MySQL
    result resource in /opt2/home3/mitas/public_html/register.php on line
    86

    It seems to be only this function mysql_num_rows( ) causing a problem,
    and the rest of the code works ok, and it adds data correctly.

    I have checked with the provider, and they are using
    PHP 4.3.10
    mySQL 4.0.26

    While im using
    PHP 5.12
    mySQL 5.0.15

    Im wondering is this function supported by the older versions ?
    Or any other ideas.

    CODE------------------------------------------------------------
    82 $conn=@mysql_co nnect( "myServer", "myUser", "myPassword " ) or die(
    "Err:Conn" );
    83 $rs = @mysql_select_d b( "myDatabase ", $conn) or die( "Err:Db" );

    84 $sql="SELECT eMail FROM tblusers WHERE eMail=\"$eMail\ " ";
    85 $rs=mysql_query ($sql,$conn);
    86 $mRecLen=mysql_ num_rows($rs);
    87 if ($mRecLen>=1) {
    88 exit("Sorry,the record exists try another" );
    89 }

    END CODE----------------------------------------------------



    Thanks
    Fish44

  • Oli Filth

    #2
    Re: error using mysql_num_rows( )


    Fish44 wrote:[color=blue]
    > Ive got the following code which works great on my localserver, but
    > when i upload it to my service provider i get an error
    >
    > "Warning: mysql_num_rows( ): supplied argument is not a valid MySQL
    > result resource in /opt2/home3/mitas/public_html/register.php on line
    > 86[/color]

    It means it exactly what it says - $rs is not a valid resource, which
    means the line that gives $rs has failed.

    echo mysql_error() after every MySQL call, to find out what the problem
    is.


    P.S. You probably want to put quotes around the e-mail address in the
    query, and also call mysql_real_esca pe_string() on $eMail.

    --
    Oli

    Comment

    • blackghost

      #3
      Re: error using mysql_num_rows( )

      Try :

      $sql="SELECT eMail FROM tblusers WHERE eMail='$eMail' ";

      Comment

      • LJB

        #4
        Re: error using mysql_num_rows( )

        If you do not have a valid resource you will always get an error.

        Try catching your resource in an "if" statement.

        If($rs) {
        do this....
        } else {
        do something else...
        }

        If nothing is selected and there are no matching rows you will
        not get a valid resource.

        Oli Filth wrote:[color=blue]
        > Fish44 wrote:
        >[color=green]
        >>Ive got the following code which works great on my localserver, but
        >>when i upload it to my service provider i get an error
        >>
        >>"Warning: mysql_num_rows( ): supplied argument is not a valid MySQL
        >>result resource in /opt2/home3/mitas/public_html/register.php on line
        >>86[/color]
        >
        >
        > It means it exactly what it says - $rs is not a valid resource, which
        > means the line that gives $rs has failed.
        >
        > echo mysql_error() after every MySQL call, to find out what the problem
        > is.
        >
        >
        > P.S. You probably want to put quotes around the e-mail address in the
        > query, and also call mysql_real_esca pe_string() on $eMail.
        >[/color]

        Comment

        • Fish44

          #5
          Re: error using mysql_num_rows( )

          Thanks for all the replies. The problem was an obvious one and i should
          have picked it up.
          It was the case was incorrect in some table names.

          Worked fine local (windows apache), but when i put it on my website,
          (apache / Linux) case was important.
          Oli your advice was spot on, espacially the mysql_errror|() function
          which gave me the name of the table at fault.

          Comment

          Working...