daveh33 Posted October 23, 2007 Share Posted October 23, 2007 <?php session_start(); include("dbconnect.php"); $username = $_POST['UserName']; $postpassword = $_POST['UserPassword']; if (!$username) { echo "You Must enter a username<br>"; $problem = "error"; } if (!$postpassword) { echo "You Must enter a password<br>"; $problem = "error"; } if ($problem=="error") { echo "<br><b>Your login was not sucessful</b><br><P>Click <a href=\"login.php\">here</a> to try again<br>"; } else { $result = mysql_query("SELECT * from registration WHERE username ='$username'") or die(mysql_error()); $row = mysql_fetch_array( $result ) or die(mysql_error()); $numrows = mysql_num_rows($result); $dbusername = $row['username']; $dbpassword = $row['password']; $mobile = $row['msid']; $email = $row['email']; if ($numrows== NULL) { echo "You username was not found<br><p>Not registered yet? Click <a href=\"register.php\">here</a> to register.. <b>its FREE!!</b><p><br>"; } if ($username=$dbusername) { echo "username match"; } if ($dbpassword==$postpassword) { $_SESSION['username'] = $username; $_SESSION['password'] = $postpassword; $_SESSION['mobile'] = $mobile; $_SESSION['email'] = $email; $sidusername = $_SESSION['username']; echo "<b>Welcome back $sidusername!</b>"; echo "<P><a href=\"download.php\">CLICK HERE TO SIMULATE A DOWNLOAD</a>"; } else { echo "Your login was not sucessful<br><P>Click <a href=\"login.php\">here</a> to try again<br>"; } } ?> Can anyone see a reason why this code will not work?? It works if username or password is blank - but if it contains data it prints an empty screen.. I had it working before so I presume there is a little bug but I cant spot in.. Can anyone else??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/74435-solved-php-login-script-not-working/ Share on other sites More sharing options...
LemonInflux Posted October 23, 2007 Share Posted October 23, 2007 Put this at the very top of the page: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/74435-solved-php-login-script-not-working/#findComment-376060 Share on other sites More sharing options...
enoyhs Posted October 23, 2007 Share Posted October 23, 2007 if ($username==$dbusername) { echo "username match"; } Mistake must be the red one... Quote Link to comment https://forums.phpfreaks.com/topic/74435-solved-php-login-script-not-working/#findComment-376063 Share on other sites More sharing options...
daveh33 Posted October 23, 2007 Author Share Posted October 23, 2007 OK, I changed it to if ($username==$dbusername) { echo "username match"; } It still displayed a blank page - I added <?php error_reporting(E_ALL); ini_set('display_errors', '1'); ?> and got the below error: - Notice: Undefined variable: problem in processlogin.php on line 18 Line 18 been: - if ($problem=="error") { I tried to add this code (before line 18) $problem = "none"; but then it just displays a blank page again.. ANY IDEAS???? Quote Link to comment https://forums.phpfreaks.com/topic/74435-solved-php-login-script-not-working/#findComment-376079 Share on other sites More sharing options...
LemonInflux Posted October 23, 2007 Share Posted October 23, 2007 Well $problem hasn't been defined, so you'd have to say, if(isset($problem)){ if ($problem=="error") { //code } } Add that in, and try it. Quote Link to comment https://forums.phpfreaks.com/topic/74435-solved-php-login-script-not-working/#findComment-376127 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.