Jump to content

Wrong password even when it's right...


Recommended Posts

So i made a login page, but whenever i enter right, wrong, or no password at all, it always displays wrong password.

I've been trying to fix it for hours, but I just can't seem to find the error.

It's like it's skipping if the password is right statement and goes straight through the else statment.

<?php
		$connection =
		mysql_connect("com-db-02.student-cit.local","***","***")
		or die (mysql_error());
		if ($connection)
		echo "Connection successful";
			else
		echo "Connection failed";
		$db = mysql_select_db("TEAM20") or die (mysql_error());
		?>
		<?php
		$_SESSION['customeremail'] = $_POST['user'];
		$_SESSION['password'] = $_POST['password'];

		
	function signIn()
	{
	session_start();
	if(!empty($_POST['user']))
	{
				$query = mysql_query("SELECT * FROM customer where customeremail = '$_POST[user]' AND password = '$_POST[password]'");
				$row = mysql_fetch_array($query);
				if(!empty($row['customeremail']) AND !empty($row['password']))
				{
				$_SESSION['customeremail'] = $row['customeremail'];
				getCustDetails();
				
				echo "Successfully login to user profile page..";
				echo "<a href=userlogin.php>Profile</a>";
				}
				else
				{
					echo "Sorry... YOU ENTERED WRONG ID AND PASSWORD";
					echo "<a href=login.html>Try Again</a>";
					
				}
				}

	}
	function getCustDetails()
	{
		$queryId = mysql_query("SELECT customerID, firstname FROM Customer WHERE customeremail = '$_POST[user]'");
		while($rowId = mysql_fetch_array($queryId))
		{
			$_SESSION['customerID'] = $rowId['customerID'];
			$_SESSION['firstname'] = $rowId['firstname'];
		}
		echo "Code: ".$_SESSION['customerID'];
		echo "Name: ".$_SESSION['firstname'];
	}
	
	
	if(isset($_POST['submit']))
	{
		signIn();
	}
?>
		
Edited by Barand
Link to post
Share on other sites

Did you check if there are any MySQL errors?

http://php.net/manual/en/function.mysql-error.php

 

At some point, you'll also want to make sure that PHP is showing all errors and warnings during the debugging process. To do that, you can add the following to the top of your script:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
 
And in case you're not aware, you'll want to look into hashing the password. More information can be found here:
Link to post
Share on other sites
This thread is more than a year old.

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.