Jump to content

[SOLVED] logging in problem


XpertWorlock

Recommended Posts

I'm trying to get a log-in page that posts back to itself, currently it signs in okay, it just acts up if the user name hasn't been created yet. 

 

So how would I go about if the userName does not exist than to do something else.

 

$userName = $_POST['userName'];
$userPassword = $_POST['userPassword'];


$result = mysql_query("SELECT * FROM users WHERE userName = '$userName'");

while($row = mysql_fetch_array($result))
  {


if ($userName != $row['userName'])
{$_SESSION['userNotExist'] = "This user does not exist";
};

if ($userPassword != $row['password'])
{$_SESSION['passwordIncorrect'] = "The password you have entered is incorrect";
};

Link to comment
https://forums.phpfreaks.com/topic/115417-solved-logging-in-problem/
Share on other sites

The thing you're doing wrong is you've made a while loop for something that should be returning one record. You should check to see if the query has returned any results, and if so, then check the password.

 

$userName = $_POST['userName'];
$userPassword = $_POST['userPassword'];

$result = mysql_query("SELECT * FROM users WHERE userName = '$userName'");
$row = mysql_fetch_array($result)
if(mysql_num_rows($result)==0){
$_SESSION['userNotExist'] = "This user does not exist";
}else{
if($userPassword != $row['password']){
	$_SESSION['passwordIncorrect'] = "The password you have entered is incorrect";
}
}

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.