Jump to content

mysql_num_rows() expects parameter 1 to be resource


xxreenaxx1

Recommended Posts

I have tired to search this up but get nothing back.. :@

 

This error is on line 18

 

on line 18 is

if (mysql_num_rows($result) == 1) {

 

Notice: Undefined variable: result in C:\xampp\htdocs\Exam_Online\Staff_login\Staff_login_process.php on line 18

 

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Exam_Online\Staff_login\Staff_login_process.php on line 18

Wrong Username or Password

 

This is the error message.

 

if (mysql_num_rows($result) == 1) {
        // Set username session variable
        $_SESSION['ID'] = $_POST['ID'];
        
         header("location:Staff_Menu.php");
}
else {
        
        echo"Wrong Username or Password";
}

 

 

The error message is self explanatory, the parameter you supplied, $result, to the function is a null. You would need to determine why $result is a null in your code.

 

Best guess, since you didn't post the relevant code prior to the error, is that you don't have a $result variable in your code.

SELECT * FROM user WHERE (Use_ID = '1') and (Use_Password = '12567')and (Rol_ID = '2')

 

This is my query. And the query actually works.

 

<?php

function fnclogin(){
  
  $con = fncOpenConnection();
  
  mysql_select_db("Examination", $con);

  $result = mysql_query("SELECT * FROM user
WHERE (Use_ID = '" . mysql_real_escape_string($_POST['ID']) . "') 
and
(Use_Password = '" . mysql_real_escape_string($_POST['password']) . "')and (Rol_ID = '1')")
or die('Cannot Execute:'. mysql_error());

  fncCloseConnection($con);
  return $result;
}




?>

 

This is my code and including this in to my php as

 

include '../Database/login.php';

$query=fncsubject();

$result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() );
echo "<select name=myselect>";

while($row=mysql_fetch_array($result)){

echo "<OPTION VALUE=".$row['Sub_ID'].">".$row['Sub_Name']."</OPTION>";
}

echo "</select>";

 

This is my code for a form and would like to call this function

 

<?PHP
function fncsubject(){
  
  $con = fncOpenConnection();
    mysql_select_db("Examination", $con);

$result = mysql_query("SELECT DISTINCT s.Sub_ID, s.Sub_Name

FROM user u, user_x_subject us, subject s, test t
WHERE u.Use_ID = '{$_SESSION['username1']}'
AND u.Use_ID = us.Use_ID
AND s.Sub_ID = us.Sub_ID
AND us.Sub_ID = t.Sub_ID")
or die('Cannot Execute:'. mysql_error());

  fncCloseConnection($con);
  return $result;
  }


?>

No offense; however, it appears you need to do a little research on functions, variables and mysql.

Here is a start - http://www.devshed.com/c/a/PHP/PHP-Functions/

 

The reason(s)? A) You are trying to use variables in your functions that are local in scope - they exist outside the function, but have either need to be passed as parameters or declared global; B), you are trying to use a result as a query.

 

There is no shame in not knowing something; BUT, if you are going to use something, it is CRITICAL to learn when, where, why and how it works. That way you can avoid problems and/or fix them when they do occur. (We all have code that doesn't work the first 20 or 30 times we try it - at least I do - I wear more ink off my keyboard fixing my mistakes than I do writing code) :)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.