PHP MySQL error: supplied argument is not a valid MySQL result resource

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mubs
    New Member
    • Mar 2007
    • 77

    PHP MySQL error: supplied argument is not a valid MySQL result resource

    Hi,

    I 'am trying to connect my sql database with my webpage for users log in. i have got this script so far but i keep getting the following error message which i cannot figure out..

    could any1 help..
    Code:
    [B]error:[/B]Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\checklogin.php on line 18
    Wrong Username or Password
    code:
    [code=php]
    <?

    $hostname_mysql _connect = "localhost" ;
    $database_mysql _connect = "website_member s";
    $username_mysql _connect = "root";
    $password_mysql _connect = "******";
    $tblname_mysql_ connect ="members";

    $mysql_connect = mysql_pconnect( $hostname_mysql _connect, $username_mysql _connect, $password_mysql _connect, $tblname_mysql_ connect) or trigger_error(m ysql_error(),E_ USER_ERROR);
    mysql_select_db ($database_mysq l_connect) or die(mysql_error ());

    $myusername = $_POST['myusername'];
    $mypassword = $_POST['mypassword'];

    $sql = "SELECT * FROM $tblname_mysql_ connect WHERE username= '$myusername' and password='$mypa ssword'";
    $result = mysql_query($sq l);

    $count = mysql_num_rows( $result); (line 18)
    if($count==1) {
    session_registe r("myusername") ;
    session_registe r("mypassword") ;
    header("locatio n:login_success .php");
    }
    else {
    echo "Wrong Username or Password";
    }

    ?>
    [/code]

    many thanx
    Last edited by Atli; Jun 26 '08, 12:26 AM. Reason: Added [code] tags.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    On your mysql query add: or die(mysql_error ())

    Code:
    $result = mysql_query($sql) or die(mysql_error());
    At a glance I can't see the problem. Maybe this will give a help.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi.

      Please use &#91;code] tags when posting your code examples. (See How to ask a question)

      &#91;code=ph p] ...PHP code goes here... &#91;/code]

      I've also changed the title of the thread to better describe it's contents.

      Thank you.

      Comment

      • Mubs
        New Member
        • Mar 2007
        • 77

        #4
        Originally posted by markusn00b
        On your mysql query add: or die(mysql_error ())

        Code:
        $result = mysql_query($sql) or die(mysql_error());
        At a glance I can't see the problem. Maybe this will give a help.

        HI... I tried the following code and i got this for an error:

        Unknown column 'password' in 'where clause'

        Comment

        • Mubs
          New Member
          • Mar 2007
          • 77

          #5
          Originally posted by Mubs
          HI... I tried the following code and i got this for an error:

          Unknown column 'password' in 'where clause'

          I just figured it out...i mis spelt the password field..

          many thanx for all posts..

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by Mubs
            I just figured it out...i mis spelt the password field..

            many thanx for all posts..
            Thought it would help.

            Remember to use those 'or die(mysql_error ())' on your mysql queries!

            Comment

            Working...