Home arrow PHP arrow Page 3 - PHP3 Introduction

HTML forms and variables - PHP

Introduction to PHP and web database interfacing with MySQL. PHP3 is an HTML-embedded scripting language allowing web developers to create dynamic, database-driven websites.

  1. PHP3 Introduction
  2. Getting your feet wet
  3. HTML forms and variables
  4. MySQL database interfacing
By: W.J. Gilmore
Rating: starstarstarstarstar / 8
March 26, 1999

print this article


Another powerful feature of PHP3.0 is it's capability of modifying variables passed from HTML forms. With these variables, one can accomplish many a feat, including such tasks as: sending web-based email, outputting information to the screen, and passing data to and from a database. Let's construct a small automated email program, demonstrating many of these capabilities:

Let's assume we have the following HTML form:

<HTML> <HEAD> <TITLE>Request for more information</TITLE> <BODY> <CENTER>Would you like more information 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="20" MAXLENGTH="30"> <P> Your email address:<BR> <INPUT TYPE="text" NAME="email" SIZE="20" MAXLENGTH="30"> <P> I prefer: <SELECT NAME="preference"> <OPTION value = Apples>Apples <OPTION value = Oranges>Oranges </SELECT> <P> <INPUT TYPE="submit" VALUE="Send it!"> </FORM> </TD></TR></TABLE></CENTER> </BODY> </HTML>

Save the above HTML as moreinfo.html.

Notice that the ACTION points to the file email.php3. This file will contain the PHP3.0 script that will carry out several commands.

The email.php3 file:

<? /* this script will handle the variables passed from the moreinfo.html file */ PRINT "<CENTER>"; PRINT "Hello, $name."; PRINT "<BR><BR>"; PRINT "Thank you for your interest.<BR><BR>"; PRINT "We will send information to $email, and have noted that you like $preference."; PRINT "</CENTER>"; ?>

Don't forget to save the above file as email.php3.

When the user types in their name and email within the HTML form, and presses the "Send it!" button, the form will call the email.php3 file, in turn returning the following output (assuming the person's name is Bill, has the email address bgates@devshed.com, and likes Apples):

Hello, Bill.

Thank you for your interest.

We will send information to bgates@devshed.com, and have noted that you like Apples.

However, our project is not yet complete, as we would not know who had inserted any information, since we are not keeping any records of what happened. Thus we would not be able to send Bill an email.

One way to do so, in turn lessening the work load of sending standard email messages manually, is by implementing PHP3.0's MAIL() command.
Syntax: void mail(string to, string subject, string message, string add_headers);
  • to - the whom the email is directed.
  • subject - phrase to be inserted in subject line of email message.
  • message - the actual message.
  • add_headers - use this to insert a string at the end of the header. (optional)

Thus, if we inserted the following commands after the last PRINT statement in the preceding script, we could automatically send email both to the person requesting information, and to the site administrator, letting us know who requested the information:

<? mail("$email", "Your request for information", "$namen Thank you for your interest!n We sell fresh corn daily over the Internet! Place your order at http://www.buycorn.com, and receive a free package of $preference!"); mail("administration@buycorn.com", "Visitor request for info.", "$name requested for information.n The email address is $email. n The visitor prefers $preference."); ?>

Important Note: The MAIL() function only works when SENDMAIL is installed on the server. In most cases, it is. However, be sure to check with your ISP before attempting to use this function.

But what happens when so many users are entering information, that you can't keep track of all of the emails? Or, you require a system to track how many prefer Apples to Oranges? The implementation of a database aids greatly in the administration of these types of data. One of the fastest database server on the market, MySQL, is a great choice for reasons of speed and ease of use, as well as it's flexibility and compatibility with PHP3.0.

The next section will deal with the incorporation of the MySQL database with PHP3.0.

>>> More PHP Articles          >>> More By W.J. Gilmore

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: