Forum Moderators: coopster
Has is it does well and does not generate any error with error E_ALL on for debugging purpose, proving that all var are declared.
FORM:
// top of form: anywhere below session_start();
if(empty($_SESSION['health']) &&!isset($_SESSION['health'])){$health="";}else{$health=$_SESSION['health'];}
// anywhere in the form
/////////////// health ///////////////////
if(empty($health)){$y=""; $n="";}
else
{
switch($health)
{
case "y":
$y="checked";
$n="";
break;
case "n";
$y="";
$n="checked";
break;
}
}
echo"<tr>
<td align='left' width='70%'><div id='strong_light'>Is the patient in good health:</div></td>
<td align='left' width='15%'> Yes<input type=radio name=health value='y' $y> </td>
<td align='left' width='15%'> No<input type=radio name=health value='n' $n>
</td></tr>";
////////////// end of health /////////////
<?
session_start();
$health = isset($_SESSION['health'])? $_SESSION['health'] : "";
echo"<tr>
<td align='left' width='70%'><div id='strong_light'>Is the patient in good health:</div></td>
<td align='left' width='15%'> Yes<input type=radio name=health value='y'";
if ($health == "y") {
echo " checked";
}
echo "> </td>
<td align='left' width='15%'> No<input type=radio name=health value='n'";
if ($health == "n") {
echo " checked";
}
echo ">
</td></tr>";
?>
If you want to get information from a previous form I would use this:
<?
$health = isset($_REQUEST['health'])? $_REQUEST['health'] : "";
echo"<tr>
<td align='left' width='70%'><div id='strong_light'>Is the patient in good health:</div></td>
<td align='left' width='15%'> Yes<input type=radio name=health value='y'";
if ($health == "y") {
echo " checked";
}
echo "> </td>
<td align='left' width='15%'> No<input type=radio name=health value='n'";
if ($health == "n") {
echo " checked";
}
echo ">
</td></tr>";
?>
Yes <input type="radio" name="health" value="y" <?php echo ($health == 'y')? 'checked':'';?>>