www.webdeveloper.com
Results 1 to 10 of 10

Thread: [RESOLVED] "Notice: Undefined index" Error

  1. #1
    Join Date
    Jul 2012
    Posts
    12

    resolved [RESOLVED] "Notice: Undefined index" Error

    Hi guys,
    I just got a new pc and copied all my php projects from the old pc.
    I also installed the latest version of XAMPP, Netbeans and PHP.

    All my projects were fine but now are showing the following errors:

    Notice: Undefined index: Submit in C:\xampp\htdocs\QuickBeam\index.php on line 8
    Notice: Undefined index: action in C:\xampp\htdocs\QuickBeam\index.php on line 63
    Notice: Undefined variable: warning in C:\xampp\htdocs\QuickBeam\index.php on line 104

    I have been working with PHP 5 for the last 2 years and never saw this error.
    I dont know if it has anything to do with the new version of PHP I installed.

    Code:
    <?php
    require_once 'inc.php';
    
    ?>
    <?php
    //DO Login when the button is clicked
    
    if("Login" == $_POST['Submit']){
    
    
    $_user = CleanData($_POST['user_name']);
    $_pwd = CleanData($_POST['user_pwd']);
    
        //both fields required
    
        if("" != $_user && "" != $_pwd)
            {
    
    
                    $hash_val = md5($_pwd);
                    $password = $hash_val;
            //set object from authentication class
    $User = strtolower($_user);
            $auth = new Registration();
            $auth->Login($User, $password);
    
            //call the helper function to find out the valaue of sucsees property
    
           if($auth->Success()){
               //set user session
               $_SESSION['regis_user'] =$User;
    
                //redirect the user
               header("location: index.php");
               exit();
             
           }else{
               $auth2 = new Authentication();
               $auth2->login($User,$password);
               if($auth2->Success()){
    
               //set user session
    
               $_SESSION['admin_user'] =$User;
    
                //redirect the user
               header("location: admin/home.php");
               exit();
               }else{
               $warning=" Incorrect username or Password!";
               }
           }
        } else{
             $warning=" Both fields are required!";
        }
    
    }
    ?>
    <?php
    
           //check for logout
    
    if("logout"==$_GET['action']){
    
        $auth=new Authentication();
        $auth->logout();
    
        $auth2=new Registration();
        $auth2->Logout();
    }
    
    ?>
    <?php PublicHeader();?>
    <?php PublicNav();?>
    
    <div id="wrapper">
    <div id="content">
        <?php if(!isset($_SESSION['regis_user'])){
        if(!isset($_SESSION['admin_user'])) {?>
    
    
    
    <fieldset id="fld_login">
    
        <form method="post" action="index.php">
    
            <table>
    
       <td>
           <label for="user_name" class="required">Name:</label>
       <input type="text" name="user_name" id="user_name" size="30" value="<?php echo $_user; ?>">
       </td>
    
       <td>
       <label for="user_pwd" class="required">Password:</label>
       <input type="password" name="user_pwd" id="user_pwd" size="30">
       </td>
    
       <td>
        <input type="submit" name="Submit" value="Login" class="button">
    
       </td>
    
       <td><?php if($warning){ echo("<p class='error_message'>{$warning}");}?></td>
      </table>
    
    </form>
    </fieldset>
    <?php }} ?>
        
    
        <div align="center"><h2>Welcome to QuickBeam</h2></div>
      
        <form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
            <input type="text" name="date" id="date">
        </form>   
    
    
    
        <div align="left"><img alt ="" src="images/myimg2.jpg" />
    
             </div>
         </div>
    </div>
    
    <?php PublicFooter();?>


    Any help is welcome,
    Mike
    Last edited by MikeSpider; 09-22-2012 at 11:16 AM.

  2. #2
    Join Date
    Sep 2012
    Posts
    14
    Just warnings to let you know those variables have not been declared.
    You might have error_reporting set to E_ALL on the new setup.

    Michael

  3. #3
    Join Date
    Feb 2012
    Location
    Tallahassee, FL
    Posts
    280
    Your error reporting mode is probably just set to strict. Notice error wont stop the script and everything could run totally fine still.

  4. #4
    Join Date
    Jul 2012
    Posts
    12
    I found in the .ini file.
    Code:
    ; error_reporting
    ;   Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
    ;   Development Value: E_ALL
    ;   Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
    I deleted the all block just an experiment, the errors are still there.
    What exactly should I change the line to?
    Also, if this is a default for the latest version of PHP, wIll the remote host have the same error reporting? I know I cannot change the remote host .ini config file.

    Thanks for your reply,
    Mike
    Last edited by MikeSpider; 09-23-2012 at 06:01 AM.

  5. #5
    Join Date
    Sep 2012
    Posts
    14
    On production machines it is usually set to not display errors, so when uploading to your host it is not a concern. I would leave it set to e_all on your testing machine, but if you really want to turn them off, you will need to go down further. That part is showing the differences between default, development and production machines. On my php.ini it is about line 461 that has the actual setting, and below that is the display_error setting, you can turn that off if you wish. I recommend it be on for your testing machine though, or else you will get a white screen and not know what happened.

    Michael

  6. #6
    Join Date
    Jul 2012
    Posts
    12
    Ok. So what happened?
    Why Am I getting this errors when I had none?
    How do I sort this out?

    Thanks,
    Mike

  7. #7
    Join Date
    Sep 2012
    Posts
    14
    You are getting it because the error_reporting or display_errors is set differently in this new installation of XAMPP. As these are just warnings, your script will work fine as it is. Some people like to have all their variables declared, which is good practice. if you do that, you will not have the warnings.

    Michael

  8. #8
    Join Date
    Jul 2012
    Posts
    12
    such a big work.
    i will have to declare all my variables before using them, and also i have problem.
    I have:

    PHP Code:
    if("logout" == $_GET['action']){

    $auth = New Authentication();
    $auth->Logout;

    I changed to :

    PHP Code:

    if(isset($_GET['action'])){
        
    $auth=new Authentication();
        
    $auth->logout();

    But what if I have more than one action on the same page?
    I have a page with several actions.

    How do i sort this?
    Thanks,
    Mike

  9. #9
    Join Date
    Sep 2012
    Posts
    14
    PHP Code:
    if((isset($_GET['action']) && $_GET['action'] == 'Logout')){ 
    Michael

  10. #10
    Join Date
    Jul 2012
    Posts
    12
    DAH! lol
    How did I forget that?
    I guess this is what happens when you give yourself some php holidays.
    I stayed away from PHP the entire month just doing vb.net. And when I got back got all this errors
    it's been a very cold welcome back indeed. 2 days and I should get back on my feet again.


    Thanks,
    Mike

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles