Today we are going to provide a PHP tutorial for the scholar of the online survey system of PHP Web tutorials, this is a simple example from HTML to PHP application, is about the online voting system code.
HTML code
<html>
<head>
<title> Questionnaire </title>
<meta http-equiv= "Content-type" content= html; charset=gb2312 ">
</head>
<body bgcolor= "#FFFFFF" >
<?php
Define display form functions
function Display_form () {
Global $PHP _self;
?>
<form action= "<?php echo $PHP _self?>" method=post>
Name: <input type=text name= "name" ><BR>
Single selection:
<input Type=radio name= "A" value= "I'm stupid" > I'm smart.
<input Type=radio name= "A" value= "I'm very stupid" > I'm stupid.
<input type=radio name= "First" value= "I'm a fool" > I'm just a dork <br>
Multiple choices:
<input type=checkbox name= "second[" value= "I like playing basketball" > I like playing basketball.
<input type=checkbox name= "second[" value= "I like swimming" > I like swimming
<input type=checkbox name= "second[" value= "I like dancing" > I like dancing.
<input type=checkbox name= "second[" value= "I like mountain climbing" > I like hiking
<input Type=hidden name= "stage" value= "Results" ><p>
<input type=submit value= "Thank you" ></p>
</FORM>
<?php
}
?>
Program start
<?php
Defining processing form functions
function Process_form ()
{
Global $name;
Global $first;
Global $second;
if ($first = ' I'm stupid ') {
$first _message = ' You're not stupid. ';
}
ElseIf ($first = ' I'm very smart ') {
$first _message = ' You're not smart. ';
}
else {
$first _message = ' You're like a smart man. ';
}
$favorite _second = count ($second);
if ($favorite _second <= 1)
{
$second _message = ' But you did wrong, repent! ';
}
ElseIf ($favorite _second > 1 && $favorite _second < 4)
{
$second _message = ' You are a sport-loving orangutan. ';
}
else {
$second _message = ' You're exercising too much, and you're already overdoing it for chimps: (';
}
echo "This is a test:<br><br> for chimpanzees";
echo "Hello!" Your name is: $name. <br><br> ";
echo "Your test results are ... $first _message $second _message ";
}
?>
<?php
if (empty ($stage)) {display_form ();}
else {process_form ();}
?>
</body>
</html>
Polling and online survey System example principle is to do a single or marquee, collect the user's information in the score.