jasha Posted March 26, 2010 Share Posted March 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196665-mysqli_query-returning-always-false-just-crazy/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 26, 2010 Share Posted March 26, 2010 Nothing you posted shows the actual call being made to the login() function. You are including a file that presumable contains the function definition, but that is not calling the function. Quote Link to comment https://forums.phpfreaks.com/topic/196665-mysqli_query-returning-always-false-just-crazy/#findComment-1032539 Share on other sites More sharing options...
jasha Posted March 26, 2010 Author Share Posted March 26, 2010 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'); } Quote Link to comment https://forums.phpfreaks.com/topic/196665-mysqli_query-returning-always-false-just-crazy/#findComment-1032540 Share on other sites More sharing options...
Mchl Posted March 26, 2010 Share Posted March 26, 2010 You're not passing connection resource to this function (third parameter) Quote Link to comment https://forums.phpfreaks.com/topic/196665-mysqli_query-returning-always-false-just-crazy/#findComment-1032542 Share on other sites More sharing options...
PFMaBiSmAd Posted March 26, 2010 Share Posted March 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196665-mysqli_query-returning-always-false-just-crazy/#findComment-1032543 Share on other sites More sharing options...
jasha Posted March 26, 2010 Author Share Posted March 26, 2010 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). Quote Link to comment https://forums.phpfreaks.com/topic/196665-mysqli_query-returning-always-false-just-crazy/#findComment-1032544 Share on other sites More sharing options...
PFMaBiSmAd Posted March 26, 2010 Share Posted March 26, 2010 No one here can help you when the code you post is not the code that exhibits the problem you want help with or when the code is a moving target. Quote Link to comment https://forums.phpfreaks.com/topic/196665-mysqli_query-returning-always-false-just-crazy/#findComment-1032545 Share on other sites More sharing options...
jasha Posted March 26, 2010 Author Share Posted March 26, 2010 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). Quote Link to comment https://forums.phpfreaks.com/topic/196665-mysqli_query-returning-always-false-just-crazy/#findComment-1032547 Share on other sites More sharing options...
Mchl Posted March 27, 2010 Share Posted March 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196665-mysqli_query-returning-always-false-just-crazy/#findComment-1032690 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.