<html> |
<!-- Demo script to process a simple form --> <html> <head> <title>Processor of simpleform2.html</title> </head> <body> <center> <?php /***** say hello to him or her *****/ $title = ($_POST['sex'] == "male") ? "Mr." : "Mrs."; echo "Hello $title "; $name = $_POST['yourname']; if (strlen($name) == 0) // Did they enter a name? echo "whoever you are."; else echo $name; echo "<P>"; /**** What likes do we share *****/ if ( isset ( $_POST['likes'] ) ) $likes = $_POST['likes']; // retrieve array of likes from POST array else $likes = null; if (count($likes) == 0) echo "Sorry you don't like anything that I like."; elseif (count($likes) == 1) echo "I like $likes[0] too."; elseif (count($likes) == 4) echo "Wow! You like everything I like."; else { echo "I also like "; $longstring = implode (", ", $likes); //build a long comma delim string $loc = strrpos ($longstring, ","); //find last comma $longstring=substr_replace($longstring," and",$loc,1); // replace last comma with "and" echo $longstring; echo ".<P>"; } /***** debugging code to show all POST data *****/ echo "<P> <hr> <P>"; print_r($_POST); echo "<hr> <P>"; ?> </body> </html> |