Suggestion for resolving undefined index
Posted: Wed May 26, 2004 3:48 pm
May I have someone's suggestion as to how to prevent PHP from reporting the following message:
Notice: Undefined index: cobrand in c:\inetpub\wwwroot\test.php on line 5
cobrand is empty
...when the code below is executed?
Thanks everyone.
Lester
///////////////////////////////////////////
<?php
$myform = $_SERVER['PHP_SELF'];
$formsent = $_GET['formsent'];
$cobrand = $_GET['cobrand'];
$theform = "
<form action=\"$myform\" method=\"get\">
<select name=\"cobrand\">
<option>mybrand1</option>
<option>mybrand2</option>
</select>
<input type=\"submit\">
<input type=\"hidden\" name=\"formsent\" value=\"true\">
</form>
";
///////////////////////////////////////////
if(isset($formsent))
{
echo "cobrand is $cobrand";
echo "formsent is $formsent";
}
else
{
echo "cobrand is empty";
}
print $theform;
?>
Notice: Undefined index: cobrand in c:\inetpub\wwwroot\test.php on line 5
cobrand is empty
...when the code below is executed?
Thanks everyone.
Lester
///////////////////////////////////////////
<?php
$myform = $_SERVER['PHP_SELF'];
$formsent = $_GET['formsent'];
$cobrand = $_GET['cobrand'];
$theform = "
<form action=\"$myform\" method=\"get\">
<select name=\"cobrand\">
<option>mybrand1</option>
<option>mybrand2</option>
</select>
<input type=\"submit\">
<input type=\"hidden\" name=\"formsent\" value=\"true\">
</form>
";
///////////////////////////////////////////
if(isset($formsent))
{
echo "cobrand is $cobrand";
echo "formsent is $formsent";
}
else
{
echo "cobrand is empty";
}
print $theform;
?>