Web Analytics Made Easy -
StatCounter HELP!!! Keep getting problem with undefined index.... - CodingForum

Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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
    "Tango says double quotes with a single ( ' ) quote in the middle"
    '$Name says single quotes with a double ( " ) quote in the middle'
    "Tango says double quotes ( \" ) must escape a double quote"
    '$Name single quotes ( \' ) must escape a single quote'

    Comment


    • #3
      I have used session_start(); at the top of the page i just didnt include it in the post sorry.

      Comment


      • #4
        If you are going to check to see if your variable has a value then you need to use the isset() function.

        Spookster
        CodingForum Supreme Overlord
        All Hail Spookster

        Comment


        • #5
          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>"
              } 

          Comment


          • #6
            if (numrows == 1)
            should be
            if ($numrow == 1)
            Spookster
            CodingForum Supreme Overlord
            All Hail Spookster

            Comment


            • #7
              haha i know. Sorry im lazy.

              Comment


              • #8
                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..

                Originally posted by RossBryan View Post
                haha i know. Sorry im lazy.
                "Tango says double quotes with a single ( ' ) quote in the middle"
                '$Name says single quotes with a double ( " ) quote in the middle'
                "Tango says double quotes ( \" ) must escape a double quote"
                '$Name single quotes ( \' ) must escape a single quote'

                Comment


                • #9
                  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.

                  Comment

                  Working...
                  X
                  😀
                  🥰
                  🤢
                  😎
                  😡
                  👍
                  👎