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
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";
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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