I`m getting this error
Notice: Undefined index: user in c:\inetpub\wwwroot\login.php on line 96
Notice: Undefined variable: message in c:\inetpub\wwwroot\login.php on line 101
Could someone please tell me where I did wrong? Here is the Code, Thanks a lot
Expand|Select|Wrap|Line Numbers
- <?php
- function confirmUser($username, $password)
- {
- global $conn;
- /* Add slashes if necessary (for query) */
- if(!get_magic_quotes_gpc()) {
- $username = addslashes($username);
- }
- /* Verify that user is in database */
- $q = "select Password from users where upper(User_Login)=upper('$username') ";
- $result = mysql_query($q,$conn);
- if(!$result || (mysql_numrows($result) < 1)){
- return 1; //Indicates username failure
- }
- /* Retrieve password from result, strip slashes */
- $dbarray = mysql_fetch_array($result);
- $dbarray['Password'] = stripslashes($dbarray['Password']);
- $password = stripslashes($password);
- /* Validate that password is correct */
- if(strtoupper($password) == strtoupper($dbarray['Password'])){
- return 0; //Success! Username and password confirmed
- }
- else{
- return 2; //Indicates password failure
- }
- }
- function checkLogin()
- {
- /* Username and password have been set */
- if(isset($_SESSION['username']) && isset($_SESSION['password']))
- {
- /* Confirm that username and password are valid */
- if(confirmUser($_SESSION['username'], $_SESSION['password']) != 0)
- {
- /* Variables are incorrect, user not logged in */
- unset($_SESSION['username']);
- unset($_SESSION['password']);
- return false;
- }
- return true;
- }
- /* User not logged in */
- else
- return false;
- }
- function displayLogin()
- {
- $end=false;
- if(isset($_POST['sublogin']))
- {
- $_POST['user'] = trim($_POST['user']);
- if(!$_POST['user'] || !$_POST['pass'])
- $message= "You Didn't Fill In All The Required Field.";
- else if(strlen($_POST['user']) > 15)
- $message= "Sorry,Username Cannot Be Longer Than 15 Characters.";
- else
- {
- //$md5pass = md5($_POST['pass']);
- $md5pass = $_POST['pass'];
- $result = confirmUser($_POST['user'], $md5pass);
- $user=$_POST['user'];
- if($result == 1)
- $message= 'That User ID Doesn\'t Exist.';
- else if($result == 2)
- $message= 'Incorrect Password, Please Try Again.';
- else
- {
- $_POST['user'] = stripslashes($_POST['user']);
- $_SESSION['username'] = $_POST['user'];
- $_SESSION['password'] = $md5pass;
- // header( 'refresh: 5; url=/main.php/' );
- echo "<META HTTP-EQUIV=Refresh CONTENT='0; URL=main.php'>";
- $end=true;
- }
- }
- }
- if(!$end)
- {
- ?>
- <form name="form1"action="" method="post">
- <table width="130" border="0" align="left" cellpadding="3" cellspacing="0">
- <tr>
- <td colspan="2"><h3 align="center">ULS Inventory Login</h3></td>
- </tr>
- <tr><td ><div align="left">User ID:</div></td><td width="100"><input name="user" type="text" onkeypress="return checkenter(window.event.keyCode)" value="<?php echo $_POST['user'] ?>" size="17" maxlength="20"></td></tr>
- <tr><td><div align="left">Password:</div></td><td><input name="pass" type="password" size="17" maxlength="20" onkeypress="return checkenter(window.event.keyCode)"></td></tr>
- <tr><td colspan="2" align="CENTER"><input type="submit" name="sublogin" value="Login"></td></tr>
- <tr><td colspan="2" align="center"><?php echo $message?></td></tr>
- </table>
- </form>
- <script type="text/javascript">
- if(document.form1.user.value=='')
- form1.user.focus();
- else if(document.form1.pass.value=='')
- form1.pass.focus();
- else
- form1.sublogin.focus();
- function checkenter($key)
- {
- if ($key==13 && document.form3.qty.value>0)
- document.form1.submit();
- }
- </script>
- <?php
- }
- }
- $logged_in = checkLogin();
- $_SESSION['logged_in']=$logged_in;
- ?>