PHP: Solution 5


Introduction | Static vs. Dynamic Websites | Using PHP on RCI or Eden | A Simple PHP Program | Practice 1 | Loops | Practice 2 | Functions | Practice 3 | Conditionals | Practice 4 | PHP and Online Forms | Practice 5 | PHP and E-mail | Practice 6 | Conclusion


The solution to practice 5 is the following:
(Note: What you had to type is in bold)

<h2>Simple Form Example</h2>

<? function show_form($first="",$last="") {  ?>

<form action="simpleForm.php3" method="post">
First Name:
<input type=text name=first value="<?echo $first?>">
<br>
Last Name:
<input type=text name=last value="<?echo $last?>">
<br> 

<input type=submit>
</form>

<? } 


if(!isset($first)) {
        show_form();
}
else {
   if(empty($first) or empty($last)) {
        echo "You did not fill in all the 
                fields, try again<p>"; 
        show_form($first,$last);
   }
   else {
        echo "Thank you, $first $last";  
   }
} 
?>



edseries@nbcs.rutgers.edu