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
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.

Link to comment
Share on other sites

erm its expecting a paramater. I've tried a few ($result,$query,$dbc,$error) but their not being accepted??

 

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

mysqli_error() expects exactly 1 parameter, 0 given

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.