Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/xxxxxx/public_html/xxxxxx/admin/index.php on line 34

This is a Login php page, each time an admin tries to login, it cannot proceed even the user/pass is correct and it give error as shown above.

Please help.

Thank you in Advance !!!

Scripts Below:

<?
session_start();
require ("inc/config.inc.php");
require ("inc/dbaccess.inc.php");
require ("classes/error.class.php");

global $mLastLogin;
$mUser_id = $HTTP_POST_VARS['txtUserName'];
$mPassword = $HTTP_POST_VARS['txtPassword'];



 //-->create my error object!


 $myerror = new error();

if(isset($mUser_id) && isset($mPassword))
{

        if(strlen($mUser_id) < 4)
        {
                $myerror->addError("Username too short (min 4 characters) ");
        }elseif(strlen($mPassword) < 4)
        {
                $myerror->addError("Password too short (min 4 characters) ");
        }
        if($myerror->getListLength() < 1)
        {
                $mUser_id = htmlspecialchars($mUser_id);
                $mPassword = htmlspecialchars($mPassword);
                $mQry = "SELECT username ,lastlogin, now() FROM 15_admin_master WHERE username='$mUser_id' AND adminpassword ='$mPassword'";
                $mResult = mysql_query($mQry);
                $mCnt = mysql_num_rows($mResult);

                if($mCnt == 0 )
                {
                        $myerror->addError("Username password combination does not match ! ");
                }else
                {
                        $mRow = mysql_fetch_row($mResult);
                        $id = $mUser_id;
                        if(!is_null($mRow[1])){
                        $mLastLogin = date('M j, Y, g:i a',strtotime($mRow[1]));
                        }else
                        {
                        $mLastLogin = date('M j, Y, g:i a',strtotime($mRow[2]));
                        }
                        session_register("id");
                        session_register("mLastLogin");

                        $mtoday = Date('Y-m-d H:i:s');
                        $mQry = "UPDATE 15_admin_master SET lastlogin = '$mtoday'";
                        $mResult = mysql_query($mQry);

                        header("location:frameset.php");
                }

        }

}


?>
<html>
<head>
<title>Welcome To  Admin ::::::::::..........</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.black11 {  font-family: Tahoma, Arial; font-size: 11px; font-style: normal; color: #000000; text-decoration: none}
.txtfld11 {  font-family: Tahoma, Arial; font-size: 11px; font-style: normal; color: #000000; text-decoration: none; height: 16px; width: 140px}
.button11 {  font-family: Tahoma, Arial; font-size: 11px; font-style: normal; color: #000000; text-decoration: none; background-color: #EAEAEA; height: 19px; width: 50px}
-->
</style>
</head>

<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="779" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="97">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="316" height="97" background="images/admin_bg.jpg">&nbsp;</td>
                <td height="97" width="463"><img src="images/admin.jpg" width="463" height="97"></td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td height="378" align="center">
                  <?
if($myerror->getListLength()>0){
?> <TABLE width="377" BORDER="0" CELLSPACING="2" CELLPADDING="1" CLASS="black11">
<TR><TD ALIGN="right"> <DIV ALIGN="LEFT"><B><FONT COLOR="#000000">Error</FONT></B></DIV></TD></TR>
<TR> <TD ALIGN="right"><DIV ALIGN="LEFT"><FONT COLOR="#FF0000"><? $myerror->showList(); ?>
</FONT></DIV></TD></TR> </TABLE><? } ?>
            <table width="377" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td height="212" background="images/table_bg.jpg" align="center">
                  <table width="70%" border="0" cellspacing="2" cellpadding="2" class="black11">
                                  <form name="form1" method="post" action="<?=$PHP_SELF?>" >
                    <tr>
                      <td align="right" width="70"><b>User Name :</b></td>
                      <td>
                        <input type="text" name="txtUserName" class="txtfld11" value="<?=$mUser_id?>" >
                      </td>
                    </tr>
                    <tr>
                      <td align="right"><b>Password :</b></td>
                      <td>
                        <input type="password" name="txtPassword" class="txtfld11">
                      </td>
                    </tr>
                    <tr>
                      <td align="right">&nbsp;</td>
                      <td><a href="#"><input type="image" src="images/login.jpg" onclick="form1.submit(); return true;">
                        </a> </td>
                    </tr>
                                        </form>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td height="25" class="black11" align="center"><b></b></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Probably somewhere an error has crept in, maybe no connection, or error in the query. Try:

$mResult = mysql_query($mQry) or die(mysql_error());

to see if anything is going wrong.

Edited 3 Years Ago by pritaeas

This article has been dead for over six months. Start a new discussion instead.