Login wont work?

Alright, I am working on my website, and while making the Login and Register page, I am encountering the error that it will not let me login after I have registered…

Heres my register.php:

<?php
require('configure.php');
$page = "extra";
$page_title = "Register";
session_start();
?>
<html>
<?php include('i/inc/header.php'); ?>
<body class="page page-id-14 page-parent page-template page-template-about-php about ">
		<div id="wrapper">
		
		<?php include('i/inc/user_nav.php'); ?>
		
		<?php include("i/inc/navigation.php"); ?>
	<!-- content-wrap -->
	<div id="content-wrap">
	
		<!-- content -->
      	<div id="content" class="clearfix">
      		
      		<div class="page-right">
				<h3>Register</h3>
				
				<div id="about-sections" class="sections">
<?php

$SUBMIT = $_POST['submit']; // Post our submit
$USERNAME[1] = $_POST['username']; // $_POST username
$PASSWORD[1] = $_POST['password']; // $_POST password
$EMAIL[1]    = $_POST['email'];    // $_POST email
$CONFIRM[1]  = $_POST['confirm'];
$USERNAME[2] = trim($USERNAME[1]); // Trim Username
$PASSWORD[2] = trim($PASSWORD[1]); // Trim Password
$EMAIL[2]    = trim($EMAIL[1]);    // Trim Email
$CONFIRM[2]  = trim($CONFIRM[1]);
$USERNAME[3] = strip_tags($USERNAME[2]); // Strip Tags
$PASSWORD[3] = strip_tags($PASSWORD[2]); // Strip Tags
$EMAIL[3]    = strip_tags($EMAIL[2]);    // Strip Tags
$CONFIRM[3]  = strip_tags($CONFIRM[2]);
$USERNAME[4] = mysql_escape_string($USERNAME[3]); // MySQL Escape String
$PASSWORD[4] = mysql_escape_string($PASSWORD[3]); // MySQL Escape String
$EMAIL[4]    = mysql_escape_string($EMAIL[3]);    // MySQL Escape String
$CONFIRM[4]  = mysql_escape_string($CONFIRM[3]);
$PASSWORD[5] = md5($PASSWORD[4]); // First MD5 of password
$PASSWORD[6] = md5($PASSWORD[5]); // Second MD5 of password
$PASSWORD[7] = md5($PASSWORD[6]); // Third MD5 of password
$CONFIRM[5]  = md5($CONFIRM[4]); // First MD5 of password
$CONFIRM[6]  = md5($CONFIRM[5]); // Second MD5 of password
$CONFIRM[7]  = md5($CONFIRM[6]); // Third MD5 of password
$USERNAME    = $USERNAME[4]; // Return our normal variable
$PASSWORD    = $PASSWORD[7]; // Return our normal variable
$EMAIL       = $EMAIL[4];    // Reture our normal variable
$IP          = $_SERVER['REMOTE_ADDR']; // Gather users IP
$CONFIRM     = $CONFIRM[7];  // $_POST confirm

if ($SUBMIT) // Check the user submits the data
{
	if ($USERNAME&&$PASSWORD&&$EMAIL&&$CONFIRM) // Check for inputs
	{
	
	if ($PASSWORD==$CONFIRM)
	{
		$connect = mysql_connect($dbhost,$dbuser,$dbpass); // Connect to PHPMyAdmin
		mysql_select_db($dbname); // Select the database
		$checkUsername = mysql_query("SELECT * FROM users WHERE username='$USERNAME'"); // Select the username table and our username
		$check1 = mysql_num_rows($checkUsername); // Gather the info
			if ($check1!=0) // Check if user exists
			{
				$ERROR = "A user has already chosen that username!";// Username entered
			}
			else
			{
				$checkEmail = mysql_query("SELECT * FROM users WHERE email='$EMAIL'");
				$check2 = mysql_num_rows($checkEmail);
				if ($check2!=0)
				{
					$ERROR = "A user has already registered with that email!"; // Email registered
				}
				else
				{
					mysql_query("INSERT INTO users VALUES ('', '$USERNAME', '$PASSWORD', '0', '0', '$IP')");
					header('Location: '.$login_url);
				}
				
			}
	}
	else
	{
	$ERROR = "Your passwords didnt match!"; // Didnt enter anything
	}
	}
	else
	{
	$ERROR = "Please fill in all the fields before attempting to register!"; // Passwords didnt match
	}
}

?>
				<?php 
				if ($ERROR)
				{
				echo "<span style='color:red'>".$ERROR."</span>";
				}
				?>
				<form action="register.php" method="post">
					<table>
					<tr>
						<td>
						Username:
						</td>
						<td>
						<input type="text" name="username" maxlength="15" />
						</td>
					</tr>
					<tr>
						<td>
						Password:
						</td>
						<td>
						<input type="password" name="password" maxlength="26" />
						</td>
					</tr>
					<tr>
						<td>
						Confirm:
						</td>
						<td>
						<input type="password" name="confirm" maxlength="26" />
						</td>
					</tr>
					<tr>
						<td>
						Email:
						</td>
						<td>
						<input type="text" name="email" maxlength="50" />
						</td>
					</tr>
					<tr>
						<td>
						 
						</td>
						<td>
						<input type="submit" name="submit" value="Reqister" />
						</td>
					</tr>
					</table>
				</form>
				</div>
			</div>
      		<div class="page-left">
      		
      							<div class="minipage">
					<img width="367" height="369" src="i/img/process-logo.jpg" class="attachment-full wp-post-image" alt="process-logo" title="process-logo" />				    
				    <div class="minipage-inner">
												<h3 class="our-history-title">What you can do:</h3>
										    	<ul>
												<li style="margin-left:30px;">&middot; View our client area!</li>
												<li style="margin-left:30px;">&middot; Purchase from us!</li>
												<li style="margin-left:30px;">&middot; Get support!</li>
												<li style="margin-left:30px;">&middot; And more!
												</ul>
				    </div>
				    				</div>
								
      		</div>
		</div><!-- [END] content -->
	</div><!-- [END] content-wrap -->
    </div><!-- [END] wrapper -->
	<hr id="sprite_cache">
	<br /><br /><br />
    </body>
</html>

It is also the action of my form.

Here is my login.php:

<?php
require('configure.php');
$page = "extra";
$page_title = "Login";
session_start();
?>
<html>
<?php include('i/inc/header.php'); ?>
<body class="page page-id-14 page-parent page-template page-template-about-php about ">
		<div id="wrapper">
		
		<?php include('i/inc/user_nav.php'); ?>
		
		<?php include("i/inc/navigation.php"); ?>
	<!-- content-wrap -->
	<div id="content-wrap">
	
		<!-- content -->
      	<div id="content" class="clearfix">
      		
      		<div class="page-right">
				<h3>Login</h3>
				
				<div id="about-sections" class="sections">
<?php

$SUBMIT = $_POST['submit']; // Post our submit
$USERNAME[1] = $_POST['username']; // $_POST username
$PASSWORD[1] = $_POST['password']; // $_POST password
$USERNAME[2] = trim($USERNAME[1]); // Trim Username
$PASSWORD[2] = trim($PASSWORD[1]); // Trim Password
$USERNAME[3] = strip_tags($USERNAME[2]); // Strip Tags
$PASSWORD[3] = strip_tags($PASSWORD[2]); // Strip Tags
$USERNAME[4] = mysql_escape_string($USERNAME[3]); // MySQL Escape String
$PASSWORD[4] = mysql_escape_string($PASSWORD[3]); // MySQL Escape String
$PASSWORD[5] = md5($PASSWORD[4]); // First MD5 of password
$PASSWORD[6] = md5($PASSWORD[5]); // Second MD5 of password
$PASSWORD[7] = md5($PASSWORD[6]); // Third MD5 of password
$USERNAME    = $USERNAME[4]; // Return our normal variable
$PASSWORD    = $PASSWORD[7]; // Return our normal variable

if ($SUBMIT) // Check the user submits the data
{
	if ($USERNAME&&$PASSWORD) // Check for inputs
	{
		$connect = mysql_connect($dbhost,$dbuser,$dbpass); // Connect to PHPMyAdmin
		mysql_select_db($dbname); // Select the database
		$query = mysql_query("SELECT * FROM users WHERE username='$USERNAME'"); // Select the username table and our username
		$numrows = mysql_num_rows($query); // Gather the info
			if ($numrows!=0) // Check if user exists
			{
				while ($row = mysql_fetch_assoc($query)) // Gather our details
				{
					$DBUSERNAME = $row['username']; // Collect DB Username
					$DBPASSWORD = $row['password']; // Collect DB Password
					$DBCLIENT   = $row['isclient']; // Check if they are a client
					$ADMIN      = $row['isadmin'];  // Check if they are a admin
				}
				if ($USERNAME==$DBUSERNAME&&$PASSWORD==$DBPASSWORD) // Check all the info matches
				{
					$_SESSION['username'] = $USERNAME; // Create user session
					if ($DBCLIENT=='1') // Check if they are a client
					{
						$_SESSION['client'] = $USERNAME; // Create the session for clients
					}
					if ($ADMIN=='1') // Check if they are admin
					{
						$_SESSION['admin'] = $USERNAME; // Create the session for admins
					}
				}
				else 
				{
				$ERROR = "You have entered the incorrect password!"; // Entered incorrect password
				}
			}
			else
			{
			$ERROR = "There is no user with the username entered!"; // Entered incorrect username
			}
	}
	else
	{
	$ERROR = "You didnt enter your username and password!"; // Didnt enter anything
	}
}

?>
				<?php 
				if ($ERROR)
				{
				echo "<span style='color:red'>".$ERROR."</span>";
				}
				?>
				<form action="login.php" method="post">
					<table>
					<tr>
						<td>
						Username:
						</td>
						<td>
						<input type="text" name="username" maxlength="15" />
						</td>
					</tr>
					<tr>
						<td>
						Password:
						</td>
						<td>
						<input type="password" name="password" maxlength="26" />
						</td>
					</tr>
					<tr>
						<td>
						 
						</td>
						<td>
						<input type="submit" name="submit" value="Login" />
						</td>
					</tr>
					</table>
				</form>
				</div>
			</div>
      		<div class="page-left">
      		
      							<div class="minipage">
					<img width="367" height="369" src="i/img/process-logo.jpg" class="attachment-full wp-post-image" alt="process-logo" title="process-logo" />				    
				    <div class="minipage-inner">
												<h3 class="our-history-title">What you can do:</h3>
										    	<ul>
												<li style="margin-left:30px;">&middot; View our client area!</li>
												<li style="margin-left:30px;">&middot; Purchase from us!</li>
												<li style="margin-left:30px;">&middot; Get support!</li>
												<li style="margin-left:30px;">&middot; And more!
												</ul>
				    </div>
				    				</div>
								
      		</div>
		</div><!-- [END] content -->
	</div><!-- [END] content-wrap -->
    </div><!-- [END] wrapper -->
	<hr id="sprite_cache">
	<br /><br /><br />
    </body>
</html>

And for anyone wondering, I took login.php and copied it to register.php and worked from there, to get everything right, then added/replaces/removed stuff.

But on my attempts to login, I get this:

You have entered the incorrect password!

I have looked at PHPMyAdmin and everything looks right, so I dont know what the problem is.

Any help? Thanks!
-Improvizionz

Wow… I feel kinda stupid, it wasnt anything in the PHP… It was inside the database, instead of putting 32 for the max VARCHAR length on password I accidently put 31. So there was my error after MD5ing the passwords several times.

Sponsor our Newsletter | Privacy Policy | Terms of Service