login problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

login problem

Post by pleigh »

i have code here for login

Code: Select all

<?php
if (isset($_POST['submit']))
{
	$message = null;
	
	//check for email/username
	if (empty($_POST['email']))
	{
		$em = false;
		$message .= "You forgot to enter your email address!";
	}
	else 
	{
		$em = $_POST['email'];
	}
	
	//check for password
	if (empty($_POST['password']))
	{
		$pw = false;
		$message .= "You forgot to enter your password!";
	}
	else 
	{
		$pw = $_POST['password'];
	}
	
	//database
	if ($em && $pw)
	{
		$query = "SELECT userID, firstname, lastname FROM userprofile WHERE username='$em' AND password='$pw'";
		$result = @mysql_query($query) or die(mysql_error());
		$row = mysql_fetch_array($result, MYSQL_NUM);
		
		if ($row)
		{
			$_SESSION['lastname'] = $row[2];									
			$_SESSION['firstname'] = $row[1];
			$_SESSION['userID'] = $row[0];
			header ("Location:  http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
			exit();
		}
		else 
		{
			$message = 'The username and password entered do not match.<br>'; 
		}
		mysql_close();
	}
	else 
	{
		$message .= "Try again.";
	}
}

if (isset($message))
{
	echo '<font color="red">' . $message . '</font>';
}
?>


<form action="<? $_SERVER['PHP_SELF']; ?>" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>Username:</td>
    <td><input type="text" name="username" value="<? if (isset($_POST['email'])) echo $_POST['email']; ?>"></td>
  </tr>
  <tr>
    <td>Password:</td>
    <td><input type="password" name="password" value="<? if (isset($_POST['password'])) echo $_POST['password']; ?>"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Submit" class="buttonformat"></td>
  </tr>
</table>
</form>
problem is that when i log in, nothing happened...no error, nothing really happened.
this snippet is included in another page...and in that page, i called the session_start() function and database connection...any help will be greatly appreciated...

thanks..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you don't have a field called "email" nor do you have a field called "submit" .. you do have "username" and "Submit" however.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

create missing fields then it will work.
Post Reply