Warning: mysql_num_rows(): supplied argument is not a valid MySQL result,

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ryanlawrence1
    New Member
    • Jun 2007
    • 2

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result,

    Heya, I get these 2 errors:
    Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in /home/themepar/public_html/changepass.php on line 20
    You have not entered all the fields
    Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in /home/themepar/public_html/changepass.php on line 34
    Sorry You failed to enter the correct old password

    I was wondering if anyone could help me, I have said where the lines are,
    Please help,
    [PHP]<?php
    // Mysql
    include ('mysql_connect .php');
    //
    $oldpass=$_POST['oldpass'];
    $newpass=$_POST['newpass'];
    $cnewpass=$_POS T['cnewpass'];
    $numrows = mysql_num_rows( $res);
    //
    if (($oldpass==NUL L)||( $newpass==NULL) ||( $cnewpass==NULL )) {
    echo "You have not entered all the fields";
    }else{
    }
    //
    if($newpass!=$c newpass) {
    echo "Passwords do not match";
    } else {
    }
    //
    $sql = "UPDATE users SET password = '".md5($newpass )."' WHERE username = '".$_SESSION['s_username']."' AND password = '".md5($oldpass )."' ";
    $res = mysql_query($sq l,$dbc) or die (mysql_error()) ;
    $numrows = mysql_num_rows( $res);
    if ($numrows >0) {
    echo "your password has been changed ";
    } else {
    echo "Sorry You failed to enter the correct old password";
    }
    mysql_query($sq l,$dbc) or die (mysql_error()) ;
    ?>[/PHP]
  • bucabay
    New Member
    • Apr 2007
    • 18

    #2
    Originally posted by Ryanlawrence1
    Heya, I get these 2 errors:
    Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in /home/themepar/public_html/changepass.php on line 20
    You have not entered all the fields
    Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in /home/themepar/public_html/changepass.php on line 34
    Sorry You failed to enter the correct old password

    I was wondering if anyone could help me, I have said where the lines are,
    Please help,
    [PHP]<?php
    // Mysql
    include ('mysql_connect .php');
    //
    $oldpass=$_POST['oldpass'];
    $newpass=$_POST['newpass'];
    $cnewpass=$_POS T['cnewpass'];
    $numrows = mysql_num_rows( $res);
    //
    if (($oldpass==NUL L)||( $newpass==NULL) ||( $cnewpass==NULL )) {
    echo "You have not entered all the fields";
    }else{
    }
    //
    if($newpass!=$c newpass) {
    echo "Passwords do not match";
    } else {
    }
    //
    $sql = "UPDATE users SET password = '".md5($newpass )."' WHERE username = '".$_SESSION['s_username']."' AND password = '".md5($oldpass )."' ";
    $res = mysql_query($sq l,$dbc) or die (mysql_error()) ;
    $numrows = mysql_num_rows( $res);
    if ($numrows >0) {
    echo "your password has been changed ";
    } else {
    echo "Sorry You failed to enter the correct old password";
    }
    mysql_query($sq l,$dbc) or die (mysql_error()) ;
    ?>[/PHP]
    The function "mysql_num_rows ()" returns the number of rows in the mysql result of a SELECT or SHOW statement.
    An UPDATE statement does not return any rows. To find out if the update actually worked, or affected some rows in the database table, then use: "mysql_affected _rows()"

    If you're doing an INSERT and want to know the id of the row the insert was made, use: "mysql_insert_i d()"

    Comment

    • epots9
      Recognized Expert Top Contributor
      • May 2007
      • 1352

      #3
      on line 10, u test if the fields are empty echo a message, but then u still continue to trying to update the database. After the echo put [PHP]exit();[/PHP] so the script doesn't not continue, or change the header to redirect to another page (ie. the page with the fields).

      Comment

      • Ryanlawrence1
        New Member
        • Jun 2007
        • 2

        #4
        I have done what you have said but i still have the same error:
        Warning: mysql_affected_ rows(): supplied argument is not a valid MySQL-Link resource in /home/themepar/public_html/changepass.php on line 20
        You have not entered all the fields
        Warning: mysql_affected_ rows(): supplied argument is not a valid MySQL-Link resource in /home/themepar/public_html/changepass.php on line 35
        Sorry You failed to enter the correct old password
        Thanks For your help anyway,
        [PHP]<?php
        session_start() ;
        if (!isset($_SESSI ON['s_username'])) {
        header("Locatio n: login.php");
        }
        ?>
        <html>
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Change Pass</title>
        </head>
        <body>
        <?php
        // Mysql
        include ('mysql_connect .php');
        //
        $oldpass=$_POST['oldpass'];
        $newpass=$_POST['newpass'];
        $cnewpass=$_POS T['cnewpass'];
        $numrows = mysql_affected_ rows($res);
        //
        if (($oldpass==NUL L)||( $newpass==NULL) ||( $cnewpass==NULL )) {
        echo "You have not entered all the fields";
        }else{
        exit();
        }
        //
        if($newpass!=$c newpass) {
        echo "Passwords do not match";
        } else {
        }
        //
        $sql = "UPDATE users SET password = '".md5($newpass )."' WHERE username = '".$_SESSION['s_username']."' AND password = '".md5($oldpass )."' ";
        $res = mysql_query($sq l,$dbc) or die (mysql_error()) ;
        $numrows = mysql_affected_ rows($res);
        if ($numrows >0) {
        echo "your password has been changed ";
        } else {
        echo "Sorry You failed to enter the correct old password";
        }
        mysql_query($sq l,$dbc) or die (mysql_error()) ;
        ?>[/PHP]

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Does mysql_connect.p hp set the value of $res? That won't work unless:
          • $res is global, or...
          • mysql_connect.p hp returns a value and you use the include statement to set the *local* variable $res:


          mysql_connect.p hp:
          [code=php]
          return mysql_connect( ... );
          [/code]

          changepass.php:
          [code=php]
          $res = include('mysql_ connect.php');
          [/code]

          Comment

          Working...