...

View Full Version : HELP!!! Problem with undefined variable....



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

$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.

myfayt
08-24-2011, 04:00 AM
Usually, it appears when your variable is not properly set.

Change this


if ($_POST['login'])
{

}

else
{
echo "$form";
}


to this


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

}

else
{
echo "$form";
}

RossBryan
08-24-2011, 04:07 AM
Thanks that works perfectly...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum