Home arrow PHP arrow Page 3 - PHP 101 (Part 2) - Shakespeare's Rose

...And Function - PHP

Now that you've got the basics of PHP variables and operators down, the second article in this series takes a look at PHP's form-processing capabilities, and introduces you to the comparison and logical operators and the "if-else" and "switch" family of conditional statements.

TABLE OF CONTENTS:
  1. PHP 101 (Part 2) - Shakespeare's Rose
  2. Form...
  3. ...And Function
  4. Operating With Extreme Caution
  5. Shakespeare In The Matrix
  6. If Not This, Then What?
  7. Fortune Smiles
  8. Submitting To The King
  9. Miscellaneous Notes
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 11
August 08, 2000

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Now for the other half of the puzzle - the "login.php4" script. Normally, this script would accept the name entered, check whether the user existed, and either grant or deny access to the site. Since we have yet to cover PHP's conditional statements and logical operators, we're not going to demonstrate that just yet - instead, we're simply going to show you how the data submitted in the first form is injected into "login.php4" and can be used in that file.

Here's "login.php4"

<html> <head> <basefont face="Arial"> </head> <body> <center> <font face="Arial" size="-1"> I wonder if you've heard of Shakespeare, <? echo $name; ?>. <p> He postulated that a rose by any other name would smell just as sweet. <p> What do you think? </font> </center> </body> </html>
And when you enter some data into the form [say "bill"] and submit it, here's what you should see:

I wonder if you've heard of Shakespeare, bill.

He postulated that a rose by any other name would smell just as sweet.

What do you think?


As you can see, whenever a form is submitted to a PHP script, all variable-value pairs within that form automatically become available for use within the script. In the example above, once the form is submitted, the variable $name is automatically created in the PHP script "login.php4", and is populated with the value entered into the form by the user.

If you were to try doing the same thing in Perl, you'd need to explicitly write code to extract and obtain the values of the variables in the form. By automatically creating and populating the variables for you, PHP simplifies your code and speeds up development time - two reasons why PHP is preferred to Perl when it comes to form processing.

Obviously, PHP also supports the POST method of form submission. All you need to change the METHOD attribute to "POST".

 
 
>>> More PHP Articles          >>> More By Vikram Vaswani and Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- 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: