Jump to content

Mysqli_query returning always false, just crazy


jasha

Recommended Posts

Hello There, as the subject suggests  i'm experiencing something i just can't sort out alone.

First of all, i'm working on mysql latest version hosted on dreamhost. I've already discussed any possible misconfiguration with the support but as far as they say my mysql server is running fine.

 

Here it is some code, i've a function called login that needs to check a username and a password in my mysql database.

 

Configuration file:

$connect = @mysqli_connect($db_host,$db_admin,$db_pwd,$dn_name);

if (mysqli_connect_errno()) {
    printf("Connection failed: %s\n", mysqli_connect_error());
    exit();
}

 

 

Than, this is the function itself:

function login($email,$pwd,$connect){
$pwd=md5($pwd);
$query = "SELECT * FROM admins WHERE email='$email' AND pwd='$pwd'";
$result = mysqli_query($connect,$query);


if(mysqli_num_rows($result)>=1){ //se ho un risultato procedo ad assegnare le variabili di sessione 
	return true;

}else { 
    return false;

}

}

 

And here the call to the function in my index.php file:

(first part)

<?php
include_once('../modules/config.php');
include_once('../modules/functions.php');
session_start();
?>

 

(function call itself)

if(!isset($_SESSION['email']) && !isset($_COOKIE['email'])){
include('./login.php');
}

 

 

 

Now, as far as i could understand the script is not working because the mysqli_query in the function returns always false. I'm not an expert but i just spent the last hours studying all possible resources and all should be configured fine, i'm passing the connection

$connect mysqli variable to the function and the mysqli_query should be working fine.

It doesn't give me any error, just false (even if i'm sure all data are matching).

 

Thanks a lot for your help.

 

Link to comment
Share on other sites

Sorry, you're right, here is the call to the function:

if(login($_POST['email'],$_POST['pwd'])){
		session_builder($_POST['email']);
			if($_POST['cookie']==1){
				if(!set_cookies($_POST['email'])){ echo "Errore nel settare i cookie, verifica le tue preferenze del browser"; };
			}
		include('./main.php');


}

 

Link to comment
Share on other sites

Since the call does not have the third parameter ($connection), you are getting a fatal runtime error.

 

Are you developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to on so that php would help you by displaying all the errors it detects. You will save a TON of time.

Link to comment
Share on other sites

Sorry still my fault, related to the code i've posted before i was passing the $connection parameter as well, what i just pasted is the code i'm using right now (i've modified it, using not mysqli anymore but mysql which is working perfectly).

Link to comment
Share on other sites

you're right, at the moment the problem is not a "moving target", i've defined it and corrected all possible errors. I do really apologize for pasting the code without the $connection var defined.

 

I do assure anyway that at the moment i posted the question the function call was well done with all the parameters and as i already wrote with the $connection var passed properly.

 

Passing over that pasting error all the rest of the code i've written in the first message it correct.

Tahsnk everyone for any possible help. I just converted the code to work with mysql_query (instead of mysqli) to check if the mistake could be in the general logic of the script (but it is not as now it's working perfectly).

 

 

Link to comment
Share on other sites

IF that's the case, thon most likely you were passing the connection resource incorrectly somehow. I'm not sure, but perhaps it should be passed through reference. I use mysqli in OO style, so the object is always passed by reference.

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.