Beginners issue with mysql_num_rows()

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

    Beginners issue with mysql_num_rows()

    I am attempting to create a login script.

    The following snippet of code:

    $query = "select * from auth where username='$user name' and
    password=passwo rd('$password') ";
    $result = mysql_query($qu ery, $db_conn);
    $num = mysql_num_rows( $result);
    echo $num;

    produces the following result:

    Warning: mysql_num_rows( ): supplied argument is not a valid MySQL
    result resource in prototype4\admi n.php on line 14

    I've searched high and low and cannot find a reason why this isn't
    working. I am however, a beginner to PHP, so please forgive me if
    there's an obvious mistake!

    Thanks in advance for any help anyone can give
  • Geoff Berrow

    #2
    Re: Beginners issue with mysql_num_rows( )

    I noticed that Message-ID:
    <f43b4914.04022 61159.79fbd94@p osting.google.c om> from David Nikel
    contained the following:
    [color=blue]
    > $query = "select * from auth where username='$user name' and
    >password=passw ord('$password' )";
    > $result = mysql_query($qu ery, $db_conn);
    > $num = mysql_num_rows( $result);
    > echo $num;[/color]

    Not a PHP question, it's a MYSQL question
    could it be password='passw ord($password)' perhaps?

    But I also found this, which I don't understand at all...
    [color=blue]
    >Password hashing in MySQL 4.1.0 differs from hashing in 4.1.1 and up. The 4.1.0 differences are:
    >
    >Password hashes are 45 bytes long rather than 41 bytes.
    >The PASSWORD() function is non-repeatable. That is, with a given argument X, successive calls to PASSWORD(X) generate different results.[/color]


    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • Pedro Graca

      #3
      Re: Beginners issue with mysql_num_rows( )

      David Nikel wrote:[color=blue]
      > The following snippet of code:
      >
      > $query = "select * from auth where username='$user name' and
      > password=passwo rd('$password') ";
      > $result = mysql_query($qu ery, $db_conn);
      > $num = mysql_num_rows( $result);
      > echo $num;
      >
      > produces the following result:
      >
      > Warning: mysql_num_rows( ): supplied argument is not a valid MySQL
      > result resource in prototype4\admi n.php on line 14[/color]

      This means the mysql_query() call produced /something/ that is not valid
      for mysql_num_rows( ) (probably your call has the same effect as
      $result = false;
      and you can't do mysql_num_rows( false);).
      [color=blue]
      > I've searched high and low and cannot find a reason why this isn't
      > working.[/color]

      I can't tell what's wrong either -- but why not let PHP/MySQL tell you?

      $result = mysql_query($qu ery, $db_conn) or die(mysql_error () . ' on ' . $query);
      [color=blue]
      > I am however, a beginner to PHP, so please forgive me if
      > there's an obvious mistake![/color]

      Maybe $username and $password are not what you think they are?

      Are these variables 'sanitized'? You don't want to pass "Mc'Donald" to
      the query "as is".

      Except for the lack of error-checking (and possibly making the variables
      safe) I see nothing wrong.
      [color=blue]
      > Thanks in advance for any help anyone can give[/color]

      You're welcome. Hope this helps.
      --
      --= my mail box only accepts =--
      --= Content-Type: text/plain =--
      --= Size below 10001 bytes =--

      Comment

      • Tom Thackrey

        #4
        Re: Beginners issue with mysql_num_rows( )


        On 26-Feb-2004, cobbler@totalis e.co.uk (David Nikel) wrote:
        [color=blue]
        > $query = "select * from auth where username='$user name' and
        > password=passwo rd('$password') ";
        > $result = mysql_query($qu ery, $db_conn);
        > $num = mysql_num_rows( $result);
        > echo $num;
        >
        > produces the following result:
        >
        > Warning: mysql_num_rows( ): supplied argument is not a valid MySQL
        > result resource in prototype4\admi n.php on line 14[/color]

        The problem is that your query is failing for some reason. That's why the
        result resource you passed to mysql_num_rows( ) is invalid.

        add the following before the semi-colon on the mysql_query line:
        or die($query.' failed because '.mysql_error() )
        the message you see will probably be meaningful to you. If not post it here
        again an someone will decipher it.

        --
        Tom Thackrey

        tom (at) creative (dash) light (dot) com
        do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

        Comment

        • David Nikel

          #5
          Re: Beginners issue with mysql_num_rows( )

          Thanks guys that's given me plenty to go on, appreciated!

          Comment

          Working...