Finker92 Posted January 7, 2012 Share Posted January 7, 2012 Hi, I created the login page below. However, when I enter details on the form I am getting a blank page. I can't figure out what is wrong. Any help/suggestions really welcome. Thanks in advance. <html> <html lang="en"> <head> <meta charset="utf-8" /> <title>LOGIN FUNCTION</title> </head> <body> <?php require('connection.php'); if(empty($_POST['name'])){ $name=NULL; echo "Sorry, you forgot to enter your username.</br>"; }else{ $name=@mysqli_real_escape_string($connection, trim($_POST['name'])); } if(empty($_POST['password'])){ $password=NULL; echo "Sorry, you forgot to enter a password.</br>"; }else{ $password=@mysqli_real_escape_string($connection, trim($_POST['password'])); } if(($name) && ($password)){ $info = "SELECT * FROM users WHERE username=$name and password=$password"; $return=@mysqli_query($connection, $info); $count_rows=@mysqli_num_rows($return); if($count_rows==1){ session_start(); if(isset($_SESSION['login'])){ header("Location:admin.php"); }else{ header("Location:login_fail.php"); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/254543-log-in-script-blank-page/ Share on other sites More sharing options...
MasterACE14 Posted January 7, 2012 Share Posted January 7, 2012 suppressing warnings/notices with '@' isn't doing you any favours. Quote Link to comment https://forums.phpfreaks.com/topic/254543-log-in-script-blank-page/#findComment-1305252 Share on other sites More sharing options...
Finker92 Posted January 7, 2012 Author Share Posted January 7, 2012 Thanks, took them off and now I am getting this error Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean I think this may be down to having the $connection in my query???? but when I remove it then I get two errors: mysqli_query() expects parameter 1 to be mysqli, string and mysqli_num_rows() expects parameter 1 to be mysqli_result, null given. Quote Link to comment https://forums.phpfreaks.com/topic/254543-log-in-script-blank-page/#findComment-1305254 Share on other sites More sharing options...
litebearer Posted January 7, 2012 Share Posted January 7, 2012 early Sat Morn and foggy-eyed but; perhaps.. change this $info = "SELECT * FROM users WHERE username=$name and password=$password"; to this $info = "SELECT * FROM users WHERE username='$name' and password='$password'"; Quote Link to comment https://forums.phpfreaks.com/topic/254543-log-in-script-blank-page/#findComment-1305255 Share on other sites More sharing options...
Finker92 Posted January 7, 2012 Author Share Posted January 7, 2012 Hi thanks, Yeah I thought it might be a problem with quotes in the SELECT too but tried putting them on and taking them off and am still getting the same result. Still getting the same two error messages when I try it. Quote Link to comment https://forums.phpfreaks.com/topic/254543-log-in-script-blank-page/#findComment-1305256 Share on other sites More sharing options...
PFMaBiSmAd Posted January 7, 2012 Share Posted January 7, 2012 The mysqli functions require the connection link in them. Literal string data values in the query statement require single quotes around them. To troubleshoot why your query is failing, you need to use mysqli_error($connection) to get mysql/php to tell you why. Use the following for your mysqli_query statement - $return=mysqli_query($connection, $info) or die(mysqli_error($connection)); Quote Link to comment https://forums.phpfreaks.com/topic/254543-log-in-script-blank-page/#findComment-1305261 Share on other sites More sharing options...
Finker92 Posted January 7, 2012 Author Share Posted January 7, 2012 OK, I swapped the positions of the $connection and $info variables in the query and was getting no errors but blank page. Then I added the code you kindly gave me and I get the same result - now I am just getting a blank page with no errors but the code is not working because the url is still the same. Maybe there is something wrong with how I am setting the $SESSION?? Quote Link to comment https://forums.phpfreaks.com/topic/254543-log-in-script-blank-page/#findComment-1305262 Share on other sites More sharing options...
Finker92 Posted January 7, 2012 Author Share Posted January 7, 2012 Hi all, Thanks for your help on this. I have to leg it to work now so will return to my conundrum later. Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/254543-log-in-script-blank-page/#findComment-1305265 Share on other sites More sharing options...
PFMaBiSmAd Posted January 7, 2012 Share Posted January 7, 2012 The position of the connection link in the mysqli_query statement should have always been the first parameter, like you had in your first post in this thread. Randomly trying things in programming, isn't programming. It just wastes a huge amount of time. Programming languages are one of the most heavily documented subjects on the planet, because you need to read and understand the documentation for each statement that you are using, before you can effectively use each statement. Your current code is not setting (assigning a value) to a session variable. Play computer and step through your logic, line by line, and make sure your logic is doing what you have defined you want it to do for each possible conditional branch. Quote Link to comment https://forums.phpfreaks.com/topic/254543-log-in-script-blank-page/#findComment-1305271 Share on other sites More sharing options...
Finker92 Posted January 8, 2012 Author Share Posted January 8, 2012 Sorry, I haven't had a chance to get back to it. Fair point on the coding, but I'm new and working around the logic is still difficult for me. Anyway, I reworked it and got it going. Thanks. I can post it up if anyone is interested. Quote Link to comment https://forums.phpfreaks.com/topic/254543-log-in-script-blank-page/#findComment-1305605 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.