Hi, the code below is for a login screen. I want to create a session so that it will pass the username that is inputted into the form onto another page. What i have done currently gives me the error.
Notice: Undefined index: UserName in C:\Program Files\Apache Group\Apache2\htdocs\Login.php on line 2
Can anyone help me get this to work?
<?php session_start();
$userName = $_POST['UserName'];
$_SESSION['userName'] = $userName;
include("header.inc");?>
<h2>Login</h2>
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
<table>
<tr><td>UserName:</td><td><input type="text" name="UserName"></td></tr>
<tr><td>Password:</td><td><input type="password" name="Password"></td></tr>
</table>
<input type="submit" name="login" value="Login">
</form>
<?
//open db connection
//Database Details
$server="localhost";
$dbusername="root";
$dbpassword="voBtGM";
$db_name="JobBase";
$connection = mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
$db = mysql_select_db($db_name, $connection) or die(mysql_error());
if (isset($_POST['login']) && $_POST['login'] == "Login") { //if the submit button is pressed...
//select rows where username AND password match the posted values
$select = mysql_query("SELECT * FROM Members WHERE UserName = '".$_POST['UserName']."' AND Password = '".$_POST['Password']."'") or die(mysql_error());
//check that record exists
if (mysql_num_rows($select) != 1) {
echo ("Oops! Your username and password did not match our records!");
} else {
$row = mysql_fetch_assoc($select);
if($row['Status'] == 1) {
print("<SCRIPT LANGUAGE=\"JavaScript1.1\">\n");
print("location = \"Advertisers.php\";\n");
print("</SCRIPT>"); }
else { print("<SCRIPT LANGUAGE=\"JavaScript1.1\">\n");
print("location = \"Seekers.php\";\n");
print("</SCRIPT>");
}
}
//close db connection
mysql_close($connection);
}
?>
</body>
</html>