473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Undefined index and Undefined variable errors

hi all,

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
  1. <?php
  2.  
  3. function confirmUser($username, $password)
  4. {
  5.  
  6.    global $conn;
  7.    /* Add slashes if necessary (for query) */
  8.    if(!get_magic_quotes_gpc()) {
  9.     $username = addslashes($username);
  10.    }
  11.  
  12.    /* Verify that user is in database */
  13.    $q = "select Password from users where upper(User_Login)=upper('$username') ";
  14.    $result = mysql_query($q,$conn);
  15.    if(!$result || (mysql_numrows($result) < 1)){
  16.       return 1; //Indicates username failure
  17.    }
  18.  
  19.    /* Retrieve password from result, strip slashes */
  20.    $dbarray = mysql_fetch_array($result);
  21.    $dbarray['Password']  = stripslashes($dbarray['Password']);
  22.    $password = stripslashes($password);
  23.  
  24.    /* Validate that password is correct */
  25.    if(strtoupper($password) == strtoupper($dbarray['Password'])){
  26.       return 0; //Success! Username and password confirmed
  27.    }
  28.    else{
  29.       return 2; //Indicates password failure
  30.    }
  31. }
  32.  
  33. function checkLogin()
  34. {
  35.  
  36.    /* Username and password have been set */
  37.    if(isset($_SESSION['username']) && isset($_SESSION['password']))
  38.    {
  39.       /* Confirm that username and password are valid */
  40.       if(confirmUser($_SESSION['username'], $_SESSION['password']) != 0)
  41.       {
  42.          /* Variables are incorrect, user not logged in */
  43.          unset($_SESSION['username']);
  44.          unset($_SESSION['password']);
  45.          return false;
  46.       }
  47.       return true;
  48.    }
  49.    /* User not logged in */
  50.    else
  51.       return false;
  52. }
  53.  
  54. function displayLogin()
  55. {
  56. $end=false;    
  57. if(isset($_POST['sublogin']))
  58. {
  59.     $_POST['user'] = trim($_POST['user']);
  60.    if(!$_POST['user'] || !$_POST['pass'])
  61.          $message= "You Didn't Fill In All The Required Field.";
  62.    else if(strlen($_POST['user']) > 15)
  63.        $message= "Sorry,Username Cannot Be Longer Than 15 Characters.";
  64.    else 
  65.    {
  66.   //$md5pass = md5($_POST['pass']);
  67.    $md5pass = $_POST['pass'];
  68.    $result = confirmUser($_POST['user'], $md5pass);
  69. $user=$_POST['user'];
  70.    if($result == 1)
  71.        $message= 'That User ID Doesn\'t Exist.';
  72.    else if($result == 2)
  73.           $message= 'Incorrect Password, Please Try Again.';
  74.    else
  75.    {
  76.            $_POST['user'] = stripslashes($_POST['user']);
  77.            $_SESSION['username'] = $_POST['user'];
  78.            $_SESSION['password'] = $md5pass;
  79.      // header( 'refresh: 5; url=/main.php/' );
  80.     echo "<META HTTP-EQUIV=Refresh CONTENT='0; URL=main.php'>";
  81.     $end=true;    
  82.  
  83.  
  84.    }
  85.    }
  86.  
  87. }
  88. if(!$end)
  89. ?>
  90. <form name="form1"action="" method="post">
  91. <table width="130" border="0" align="left" cellpadding="3" cellspacing="0">
  92. <tr>
  93.   <td colspan="2"><h3 align="center">ULS Inventory Login</h3></td>
  94.   </tr>
  95. <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>
  96.  
  97. <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>
  98.  
  99. <tr><td colspan="2" align="CENTER"><input type="submit" name="sublogin" value="Login"></td></tr>
  100. <tr><td colspan="2" align="center"><?php echo $message?></td></tr>
  101.  
  102. </table>
  103. </form>
  104. <script type="text/javascript">
  105. if(document.form1.user.value=='')
  106.         form1.user.focus();
  107. else if(document.form1.pass.value=='')
  108.         form1.pass.focus();
  109. else 
  110.         form1.sublogin.focus();
  111. function checkenter($key)
  112. {
  113.     if ($key==13 && document.form3.qty.value>0)
  114.         document.form1.submit();
  115. }                
  116. </script>
  117. <?php
  118.  
  119.  }
  120. $logged_in = checkLogin();
  121. $_SESSION['logged_in']=$logged_in;
  122. ?>
  123.  
Mar 12 '08 #1
4 4038
Markus
6,050 Expert 4TB
This means you are calling an index in an array which doesnt exist (user) the $_POST['user'] hasnt been set.

Same applies for the variable, youre calling a variable that doesnt exist.
Mar 12 '08 #2
ronverdonk
4,258 Expert 4TB
These are not errors, just notices. To check before outputtinng it, you can do this:
[php]<?php echo (isset($_POST['user'])) ? $_POST['user'] : ""; ?>[/php]
Ronald
Mar 12 '08 #3
TheServant
1,168 Expert 1GB
In your form:
[HTML]<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">[/HTML]
I am confused at how you have <?php echo $_POST['user'] ?> as the value, but nothing has been posted at this stage? This is the input? Maybe I have missed something?
Mar 12 '08 #4
ronverdonk
4,258 Expert 4TB
In your form:


I am confused at how you have <?php echo $_POST['user'] ?> as the value, but nothing has been posted at this stage? This is the input? Maybe I have missed something?
I noticed that also, but probably he hasn't shown all the code. Naughty!

Ronald
Mar 12 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: news.bigpond.com | last post by:
getting errors Notice: Undefined index: name in F:\uni\Software engineering\assignment4\guestbook.php on line 6 the variable $name is declared as $name = _POST; What could be causing this?...
7
by: Coder Droid | last post by:
I decided to run some code with errors set to E_ALL, just to see what I would run across. It caught a few things, but 90% or better of the messages were of the 'undefined' kind: PHP Notice: ...
9
by: petermichaux | last post by:
Hi, I am curious about how php deals with the following situation where I use an undefined index into an array. PHP seems to be behaving exactly how I want it to but I want to make sure that it...
4
by: John Oliver | last post by:
PHP Notice: Undefined index: name in /home/www/reformcagunlaws.com/new.php on line 6 PHP Notice: Undefined index: address in /home/www/reformcagunlaws.com/new.php on line 7 PHP Notice: ...
3
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice:...
2
by: Reggie | last post by:
am trying to create a a upload file.am uploading files ok but i recieve this message. Notice: Undefined variable: uploaded_size in /home/fhlinux169/c/ clashoff.co.uk/user/htdocs/upload.php on...
5
by: siyaverma | last post by:
Hi, I am new to php, i was doing some small chnages in a project developed by my collegue who left the job and i got the responsibility for that, After doing some changes when i run it on my...
5
by: movieking81 | last post by:
Another PHP newbie here, I trolled the boards here trying some of the different solutions but I keep getting the errors over an over. maybe my problem is specific. I keep getting the following when...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.