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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RossBryan
Forum Newbie
Posts: 19
Joined: Fri Aug 19, 2011 3:03 pm

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

Post by RossBryan »

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

Does anyone know what the problem seems to be this time?
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

Code: Select all

<?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
xtiano77
Forum Commoner
Posts: 72
Joined: Tue Sep 22, 2009 10:53 am
Location: Texas

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

Post by xtiano77 »

Did you declare those

Code: Select all

$_SESSION
variables? Did you start the session

Code: Select all

session_start( )
prior to calling those variables? Is this the whole code for the page so we can have a better idea?
RossBryan
Forum Newbie
Posts: 19
Joined: Fri Aug 19, 2011 3:03 pm

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

Post by RossBryan »

Yes i have now, and also used isset() to initialize the session variables user and id:

Code: Select all

session_start();

if( isset($_SESSION['user']) ) 
{
   $username = $_SESSION['user']; 
}
if( isset($_SESSION['id']) ) 
{
   $userid = $_SESSION['id'] ;
}
So its resolved and all working fine now, thanks for taking the time out to look at my post.
Post Reply