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 9 of 9
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts

    HELP!!! Keep getting problem with undefined index....

    I really dont get it now i keep having this problem and there always seems to be a different solutiion. Im defining variables and yet its telling me that they arent defined; so confusing :s

    Notice: Undefined index: user in C:\xampp\htdocs\Care2Share\design\status.php on line 4
    Notice: Undefined index: id in C:\xampp\htdocs\Care2Share\design\status.php on line 5
    PHP Code:
    <?php 

    $username 
    $_SESSION['user'];
    $userid $_SESSION['id'] ;

    if (
    $username)
    {
            echo 
    "You are logged in as $username"
    }

    else
    {
            echo 
    "<form action='loginC2S.php' method='POST' >
     
    <table style='margin-left: auto; margin-right: auto;'>
    <tr>
            <td><input type='text' id='usernamebox' name='user' tabindex='1' value='Username' class='textbox' onfocus='usernamebox_focus();' onblur='usernamebox_blur();'></td>
            <td><a href='register.php'>Register</a></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>"
    ;
    }

    ?>
    I know coding can be frustrating at times but im seeing myself not having any hair left the way this is going lol

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    You should ALWAYS use session_start() at the top of ANY script which uses sessions.

    session_start DOES NOT just start sessions, it also RESUMES existing sessions (in other words reopens them). It's clearly stated on the php manual
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I have used session_start(); at the top of the page i just didnt include it in the post sorry.

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    If you are going to check to see if your variable has a value then you need to use the isset() function.

    http://php.net/manual/en/function.isset.php
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    New Coder
    Join Date
    Aug 2011
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks that worked great but ended up causing another problem with another section of coding in an associated file:

    Notice: Use of undefined constant numrows - assumed 'numrows' in C:\xampp\htdocs\Care2Share\loginC2S.php on line 62

    PHP Code:
    $numrow =mysql_num_rows($query); 
         

        if (
    numrows == 1
        { 
            
    $rows mysql_fetch_assoc($query); 
            
    $dbuser $rows['username']; 
            
    $dbid $rows['id']; 
             
            
    //logs user in         
            
    $_SESSION['user'] =$dbuser
            
    $_SESSION['id'] = $dbid;     
            echo 
    "<center>You have been logged in.</center>"
        } 

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    if (numrows == 1)
    should be
    if ($numrow == 1)
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • Users who have thanked Spookster for this post:

    RossBryan (08-25-2011)

  • #7
    New Coder
    Join Date
    Aug 2011
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts
    haha i know. Sorry im lazy.

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by RossBryan View Post
    I have used session_start(); at the top of the page i just didnt include it in the post sorry.
    No offence but if session_start was used in your code why on earth didn't you show it? .. oh hang on... i see..

    Quote Originally Posted by RossBryan View Post
    haha i know. Sorry im lazy.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #9
    New Coder
    Join Date
    Aug 2011
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts
    lol your a funny guy.... don't please...*shaking my head*

    Thanks for taking the time to look at my post anyway and giving me a hand.


  •  

    Posting Permissions

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