Jump to content

[SOLVED] php login script not working


daveh33

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/74435-solved-php-login-script-not-working/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

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