Jump to content

[SOLVED] mysqli_num_rows problem


jas4

Recommended Posts

Hi hopefully you can help me:

 

I'm trying to run a query and run it through a function to validate before it gets near my database.

 

the error I get is:

An error has occured in script 'C:\wamp\www\other\login.php' on line '19'

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

 

The query section is: (the line with the wrong syntax is in this part(half way down)

	$memberEmail =escape_data($_POST['loginEmail']);
		$memberPassword = escape_data($_POST['loginPassword']);

		$query =("SELECT memberid, memail, mfirstName, mactive FROM members WHERE  memail = $memberEmail AND mpassword = ".  (md5($memberPassword)));

		$result = mysqli_query($dbc,$query);


		if (mysqli_num_rows($result) == 1) 
		{
			$row = mysqli_fetch_assoc($result);
			if($row['mactive'] == 1)
			{
			  session_start();
				$_SESSION['id'] = $row['memberid'];
          $_SESSION['logged_in'] = TRUE;
				header("Location: success.php");
			}

 

and the function in the config file that I made is:

 

function escape_data($data){
    
    //Need the connection:
    global $dbc;
    
    //Address the magic quotes.
    if(ini_get('magic_quotes_gpc')){
      $data =stripslashes($data);
      }
      
      //Trim and escape:
      return mysqli_real_escape_string($dbc, trim($data));
      
      } //End of escape_data() function

 

I'm sure the syntax is slightly wrong, but I just cant figure out why its not being accepted

 

 

Link to comment
https://forums.phpfreaks.com/topic/62480-solved-mysqli_num_rows-problem/
Share on other sites

An error has occured in script 'C:\wamp\www\other\login.php' on line '19'

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

 

the $result being passed is not a mysql query result (so the error msg says...)

 

change this...

 

$result = mysqli_query($dbc,$query);

 

to...

 

$result = mysqli_query($dbc,$query) or die(mysqli_error());

 

and see if it spits out an error.

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.