I keep getting an error. Notice: Undefined index: username in E:\LocalUser\Mitchell\Cattle\Main.php on line 61
I am just trying to have it pass the username of the person that logged in to the next page so that I can use the variable $username to pull information from the database for that user.
Below is the code for the login page.
<?php require_once('../Connections/Manager.php'); ?>
<?php
mysql_select_db($database_Manager, $Manager);
$query_Login = "SELECT * FROM login";
$Login = mysql_query($query_Login, $Manager) or die(mysql_error());
$row_Login = mysql_fetch_assoc($Login);
$totalRows_Login = mysql_num_rows($Login);
?>
<?php
// *** Validate request to login to this site.
session_start();
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
$GLOBALS['PrevUrl'] = $accesscheck;
session_register('PrevUrl');
}
if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['Password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "/Cattle/Main.php";
$MM_redirectLoginFailed = "/Cattle/Again.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_Manager, $Manager);
$LoginRS__query=sprintf("SELECT Username, Password FROM login WHERE username='%s' AND Password='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
$LoginRS = mysql_query($LoginRS__query, $Manager) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
//declare two session variables and assign them
$GLOBALS['MM_Username'] = $loginUsername;
$GLOBALS['MM_UserGroup'] = $loginStrGroup;
//register the session variables
session_register("MM_Username");
session_register("MM_UserGroup");
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Your pages title here</title>
<link rel=stylesheet type="text/css" href="style.css">
</head>
<body bottommargin="0" leftmargin="0" rightmargin="0" topmargin="0" background="img/background.jpg">
<table height="123" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top">
<!----- insert logo below ------------------------------------------>
<td><img src="img/templogo.jpg" width="574" height="123" border="0" alt=""></td>
<!------------------------------------------------------------------>
<td width="100%" background="img/topbg.jpg"> </td>
</tr>
</table>
<table height="40" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top">
<td width="100%" background="img/topbar.jpg"> </td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top">
<td width="201"><BR>
<!----- menu, insert links below ------------------------------------------>
» <a href="http://www.MitchellMeffert.com/Cattle">Home</a><BR>
<img src="img/menubar.jpg" width="201" height="11" border="0" alt=""><BR>
» <a href="http://www.MitchellMeffert.com/Cattle/Login.php">Login</a><BR>
<img src="img/menubar.jpg" width="201" height="11" border="0" alt=""><BR>
» <a href="http://www.MitchellMeffert.com/Cattle/Signup.php">Signup</a><BR>
<img src="img/menubar.jpg" width="201" height="11" border="0" alt=""><BR><BR>
<img src="img/menubar.jpg" width="201" height="11" border="0" alt=""><BR>
<!-------------------------------------------------------------------------->
</td>
<td width="100%">
<table width="100%" cellpadding="10" cellspacing="0" border="0">
<tr valign="top">
<td>
<!----- content, insert text and content below ------------------------------------------>
<form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<p><Center><h2>Login</h2></Center>
</p>
<p>Username:
<input type="text" name="username">
</p>
<p>Password:
<input type="text" name="Password">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<?
if (isset($_POST['username']))
{
$username= $_POST['username'];
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($Login);
?>
Below is the code for the page that you go to when you have loged in.
<?php require_once('../Connections/Manager.php'); ?>
<?php
session_start();
mysql_select_db($database_Manager, $Manager);
$query_Manager = "SELECT * FROM login";
$Manager = mysql_query($query_Manager, $Manager) or die(mysql_error());
$row_Manager = mysql_fetch_assoc($Manager);
$totalRows_Manager = mysql_num_rows($Manager);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Your pages title here</title>
<link rel=stylesheet type="text/css" href="style.css">
</head>
<body bottommargin="0" leftmargin="0" rightmargin="0" topmargin="0" background="img/background.jpg">
<table height="123" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top">
<!----- insert logo below ------------------------------------------>
<td><img src="img/templogo.jpg" width="574" height="123" border="0" alt=""></td>
<!------------------------------------------------------------------>
<td width="100%" background="img/topbg.jpg"> </td>
</tr>
</table>
<table height="40" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top">
<td width="100%" background="img/topbar.jpg"> </td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top">
<td width="201"><BR>
<!----- menu, insert links below ------------------------------------------>
» <a href="http://www.MitchellMeffert.com/Cattle">Home</a><BR>
<img src="img/menubar.jpg" width="201" height="11" border="0" alt=""><BR>
» <a href="http://www.MitchellMeffert.com/Cattle/Login.php">Login</a><BR>
<img src="img/menubar.jpg" width="201" height="11" border="0" alt=""><BR>
» <a href="http://www.MitchellMeffert.com/Cattle/Signup.php">Signup</a><BR>
<img src="img/menubar.jpg" width="201" height="11" border="0" alt=""><BR><BR>
<img src="img/menubar.jpg" width="201" height="11" border="0" alt=""><BR>
<!-------------------------------------------------------------------------->
</td>
<td width="100%">
<table width="100%" cellpadding="10" cellspacing="0" border="0">
<tr valign="top">
<td>
<!----- content, insert text and content below ------------------------------------------>
<? echo "Welcome,
". $_SESSION['username'] ."";?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($Manager);
?>