What fruit do you like to eat?
Name:
Email:
Please choose: Apple orange Pear
Coconut Watermelon Banana
Here's how to build a PHP program to receive and process information from diaocha.htm forms
diaocha.php
<?php
/* Define some related variables for the following mysql_connect () function with the */
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "MyDB";
/* Used to store the email address of the site supervisor * *
$adminaddress = "webmaster@youweb.com";
/* This is the table we just created to store user data.
$userstable = "Infostar";
/* Set up the connection below * *
Mysql_connect ($hostname, $username, $password) or die ("Unable to connect database");
/* Below Select database MyDB, precede function with (@) symbol will suppress error message display.
@mysql_select_db ("$dbname") or Die ("Unable ro Select database");
print "<center>";
Print "Hello: $name.";
print "<br><br>";
Print "Your email is: $email <br><br>";
Print "Thank you for your participation <br><br>";
/* Insert the information into the table Infostar * *
/* Because the database table was previously selected with the mysql_select_db function. Therefore, the following is not required in the input table name * *
$query = "INSERT into $userstable VALUES (' $name ', ' $email ', ' $choice ')";
$result =mysql_query ($query);
Print "Your information we have saved to the database.";
/* Close Database connection/*
Mysql_close ();
?>
Note: If you are programming as above: Define string variables at the outset, it is easier to modify them.
We have put the information into the database, so how can we browse the data?
Next, we try to make a list of all the friends who like to eat Apple, set up apple.php file
apple.php
<?php
/* Define some related variables for the following mysql_connect () function with the */
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "MyDB";
$userstable = "Infostar";
/* Set up the connection below and select the database * *
Mysql_connect ($hostname, $username, $password) or die ("Unable to connect database");
@mysql_select_db ("$dbname") or Die ("Unable ro Select database");
* * Select all users who like Apple.
$query = "SELECT * from $userstable WHERE choice= ' Apple '";
$result =mysql_query ($query);
/* Calculate how many of these users * *
$number =mysql_num_rows ($result);
* * Show the results
$i = 0;
IF ($number ==0) {
Print "<center><p> no one likes Apple </center>";}
else{
Print "<center><p> like to eat Apple users have: $number <br><br>";
while ($i < $number):
$name =mysql_result ($result, $i, "name");
$email =mysql_result ($result, $i, "email");
Print "$name like to eat Apple <br>";
print "Mail address: $email <br><br>";
$i + +;
Endwhile;
print "</center>";
}
?>
Call apple.php in the browser to see what appears.
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.