Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts

    HELP!!! Problem with undefined variable....

    Hey can about tell me why im getting the following undefined notice for the code straight after:

    "Notice: Undefined index: login in C:\xampp\htdocs\Care2Share\loginC2S.php on line 43"

    PHP Code:
    <?php

    $form 
    "<form action='index.php?login=yes' method='POST'>
     <table>
    <tr>
        <td><input type='text' id='usernamebox' name='user' tabindex='1' value='Username' class='textbox' onfocus='usernamebox_focus();' onblur='usernamebox_blur();'></td>
    </tr> 
    <tr>
        <td><input type='text' id='passwordbox' name='pass' tabindex='2' value='Password' class='textbox' onfocus='passwordbox_focus();' onblur='passwordbox_blur();' /></td>
        <td><input type='submit' name='login' value='login' tabindex='3' class='button'> </td>
    </tr>
    </table>
    </form>"
    ;

    if (
    $_POST['login'])
    {
            
    }

    else
    {
        echo 
    "$form";
    }

    ?>
    I'm quite sure im collecting the text name 'login' from inside the definition of the variable $form. But im still getting that notice in the browser for the part of the code where im attempting to apply $_POST['login'] in the if statement condition.

    Can anyone help? I am new to this so is probably a pretty straight forward solution.

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,501
    Thanks
    72
    Thanked 105 Times in 104 Posts
    Usually, it appears when your variable is not properly set.

    Change this

    PHP Code:
    if ($_POST['login'])
    {
            
    }

    else
    {
        echo 
    "$form";

    to this

    PHP Code:
    if (isset($_POST['login']))
    {
            
    }

    else
    {
        echo 
    "$form";


  • Users who have thanked myfayt for this post:

    RossBryan (08-24-2011)

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks that works perfectly...


  •  

    Posting Permissions

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