PHP3 Introductory Tutorials HTML forms and variables

Source: Internet
Author: User
Tags html form insert mail mysql variables php3 file



Like an ASP, PHP3.0 can also easily handle HTML forms and variables, and each value sent from a form automatically assigns the corresponding variable values based on the form's name attribute (name), which can be referenced directly in the PHP3 script. This feature is widely used in WEB applications, and the client data acquisition is basically implemented in this way. Below, we build a small automated mail-sending program to demonstrate this feature of PHP3.0.

Here is an example of an HTML form:
< html>
< head>
< title> survey Page </title>
< body>

< center> do you want to know more about our company? < p>
< TABLE WIDTH = 400>< tr>< TD align = right>
< FORM action= "email.php3" method= "POST" >
Your name: < br>
< INPUT type= "text" name= "NAME" size= "maxlength=" >
< p>
Your email address: < br>
< INPUT type= "text" name= "email" size= "maxlength=" >
< p>
Which do you like better, oranges or apples?
< select Name= "preference" >
< option value = apples> Apple < OPTION value = oranges> Orange
</select>
< p>
< INPUT type= "submit" value= "Send" >
</form>
</td></tr></table></center>
</body>


Save this HTML file as "moreinfo.html".

You should notice that the FORM's ACTION attribute is pointed to email.php3. This file will contain scripts to execute server-side commands:

EMAIL.PHP3 file:
<?
/* This script will be used to process the information sent from the moreinfo.html file.
PRINT "< center>";
PRINT "Hello, $name."
PRINT "< br>< br>";
PRINT "Thank you for your participation < br>< br>";
PRINT "We will issue validation information to $email";
PRINT "</center>";
?>


When the user fills in the name and email address in the HTML form and presses the "Send" button, the form will call the Email.php3 file, and the PHP3 script will return the input (assuming that the user's name is Wang Peng and the EMail address is wp@263.ne T, and like Apple):

Hello, Wang Peng.

Thank you for your participation.

We will issue validation information to Wp@263.net

However, until now our plan has not been completed, we should not record any user information, we do not know how to send this email.

One way to solve this is to use the PHP3.0 mail () function.

Syntax: void mail (string to, string subject, String message, string add_headers);

Here's what these parameters mean:

* To-Specify the address of the email recipient's fuel tank.

* Subject-The contents of the subject title bar of the message.

* Message-the body of the mail, which is what to send.

* Add_headers-This parameter is optional and uses it to insert a string at the end of the message header.

So, if you add the following script to the previous script and insert it behind the last PRINT statement, we can automatically send the message after the display:
Mail ("$email", "Your Request for Information", "$namen
Thank for your interest!n
We sell fresh corn daily over the internet!
Place your in http://www.buy.com,
and receive a FREE package of $preference! ");
Mail ("administration@buy.com",
"Visitor Request for info.",
"$name requested for INFORMATION.N
The email address is $email. N
The visitor prefers $preference. ");
?>


Notably, the Mail () function works only if the SENDMAIL is also installed on the server. In most cases, SENDMAIL is installed with PHP3.0. But if the mail () function doesn't work, you should check to see if SENDMAIL is installed.

But if a lot of people send their forms, it's impossible to save one by one of them with just the above method. Perhaps, you want to count how many people like to eat apples, how many people like to eat oranges. For such tasks, it is possible to use a database to store the data. MySQL can be said to be one of the fastest database servers, when your application is more sensitive to speed, MySQL is a better choice, and, it and PHP3.0 compatibility is also better.

-->



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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.