PHP
  Home arrow PHP arrow Page 3 - PHP3 Introduction
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP3 Introduction
By: W.J. Gilmore
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 8
    1999-03-26


    Table of Contents:
  • PHP3 Introduction
  • Getting your feet wet
  • HTML forms and variables
  • MySQL database interfacing

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    PHP3 Introduction - HTML forms and variables
    ( Page 3 of 4 )

    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
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT