Php Getting Started Tutorial: using a form survey instance

Source: Internet
Author: User
Tags php tutorial
The code is as follows: Copy code

<Html>
<Head>
<Title> php Tutorial: using a form survey instance </title>
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312">
</Head>
<Body bgcolor = "# ffffff">

<? Php
// Define the display form function
Function display_form (){

Global $ php_self;

?>
<Form action = "<? Php echo $ php_self;?> "Method = post>
Name: <input type = text name = "name"> <br>
Single choice:
<Input type = radio name = "first" value = "I'm stupid"> I'm smart.
<Input type = radio name = "first" value = "I am stupid"> I am stupid
<Input type = radio name = "first" value = "I am a dumb"> I am a dumb <br>

Multiple options:
<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 hiking"> I like hiking.
<Input type = hidden name = "stage" value = "results"> <p>
<Input type = submit value = "thank you"> </p>
</Form>

<? Php
}
?>

// Start the program

<? Php

The code is as follows: Copy code

// Define the processing Form function
Function process_form ()
{
Global $ name;
Global $ first;
Global $ second;

If ($ first = 'I am dump '){
$ First_message = 'you are not stupid. ';
}
Elseif ($ first = 'I am smart '){
$ First_message = 'you are not smart. ';
}
Else {
$ First_message = 'You are like a smart person. ';
}

$ Favorite_second = count ($ second );
If ($ favorite_second <= 1)

$ Second_message = 'but you have done something wrong. Sorry! ';
}
Elseif ($ favorite_second> 1 & $ favorite_second <4)
{
$ Second_message = 'you are a sports-loving orangutan. ';
}
Else {
$ Second_message = 'You have been exercising too much, and you have been over-exercising for the orangutan :(';
}

Echo "this is a test for orangutan: <br> ";
Echo "Hello! Your name is $ name. <br> ";
Echo "your test result is ..... $ First_message $ second_message ";
}
?>

<? Php
If (empty ($ stage) {display_form ();}
Else {process_form ();}
?>

</Body>
</Html>

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.