...

View Full Version : HELP!!! Keep getting problem with undefined index....



RossBryan
08-25-2011, 01:03 AM
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

$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

tangoforce
08-25-2011, 01:08 AM
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 ;)

RossBryan
08-25-2011, 01:13 AM
I have used session_start(); at the top of the page i just didnt include it in the post sorry.

Spookster
08-25-2011, 01:18 AM
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

RossBryan
08-25-2011, 01:27 AM
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



$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>";
}

Spookster
08-25-2011, 01:30 AM
if (numrows == 1)
should be
if ($numrow == 1)

RossBryan
08-25-2011, 01:38 AM
haha i know. Sorry im lazy.

tangoforce
08-25-2011, 02:02 AM
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..


haha i know. Sorry im lazy.

:D

RossBryan
08-25-2011, 02:06 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum