YNOT
  • Home
  • Industry News
    • Adult Business News
    • Adult Novelty News
    • YNOT Magazine
    • EU News
    • Opinions
    • Picture Galleries
  • PR Wire
    • Adult Company News
    • Adult Retail News
    • Adult Talent News
    • Adult Videos News
  • Podcasts
  • Industry Guides
    • Adult Affiliate Guide
    • Affiliate Marketing for Beginners
    • Top Adult Traffic Networks
    • Top Adult PR Agents
    • Funding an Adult Business
  • Business Directory
    • View Categories
    • View Listings
    • Submit Listing
  • Newsletters
  • Industry Events
    • Events Calendar
    • YNOT Cam Awards | Hollywood
    • YNOT Awards | Prague
    • YNOT Cammunity
    • YNOT Summit
    • YNOT Reunion
  • Login with YNOT ID
YNOT University: Educational articles and tutorials

Introduction to PHP and MYSQL – Part 3

Posted On 25 Jul 2002
By : admin

It’s All In Your Form

[Part 1] [Part 2]

One of the most common uses of PHP is the dynamic processing of form variables. Just like watching a major league baseball player stepping up to the plate, a great deal of the PHP game is all in your form.It’s All In Your Form

[Part 1] [Part 2]

One of the most common uses of PHP is the dynamic processing of form variables. Just like watching a major league baseball player stepping up to the plate, a great deal of the PHP game is all in your form. HTML forms are used on the World Wide Web for a variety of purposes that range from the sign-up and authentication of their member base, to the most complex online e-commerce applications. Since this rudimentary skill will be used in practically every website you work on, I have dedicated an entire article to the use and power of form processing.

The Wind Up… The Pitch

To begin, let’s create a simple HTML page with a form on it. The following HTML page contains a basic form and some of the basic input field types that you will use.

<HTML><HEAD><TITLE>PHP Form Basics</TITLE></HEAD>
<BODY>
<FORM ACTION=”formprocess.php” METHOD=POST>
<center>
Page Title: <INPUT TYPE=TEXT NAME=”page_title” SIZE=40><br>
User Name: <INPUT TYPE=TEXT NAME=”username” SIZE=20><br>
Password: <INPUT TYPE=PASSWORD NAME=”password” SIZE=20><br>
<INPUT TYPE=SUBMIT NAME=”SUBMIT” VALUE=”Submit Me”>
</center>
</FORM>
</BODY>
</HTML>

The <FORM> tags will define where your form begins and ends. The ACTION parameter of the <FORM> tag controls what page will be the recipient of this form’s data when the submit button is pressed. The METHOD parameter controls the manner in which data is transmitted between your pages. I have chosen, and nearly always choose to send data via the POST method because of the transparency of the data. If I just lost you, let me take a moment to explain.

There are two alternatives you have when using the METHOD parameter of the <FORM> tags, POST and GET. To be honest, it won’t really make that much of a difference to you when you are first starting out with your exploration of dynamic form processing. This is because both methods do the most important thing you are attempting to accomplish, namely, delivering the data between forms. As you start to write more and more sophisticated applications the distinction will become readily apparent.

The difference between these two methods is how they deliver the data between forms. POST sends information without the user seeing any data while the GET sends all of the form variables as part of the URL that is passed into the address bar of the user’s browser.

URL using POST
http://www.yoursite.com/formprocess.php

URL using GET
http://www.yoursite.com/formprocess.php?page_title=PHPFun&username=Midnight&password=mypassword

Using POST will always insure that your users have a clean URL to look at in their browser, and prevents the display of unwanted information such as INPUT fields that use the TYPE=HIDDEN parameter to pass along global scope information in the stateless environment of the World Wide Web. It also insures that it will give the least amount of information to those individuals that would seek to break into your system, or feed it with invalid data in an attempt to disrupt the normal flow of information.

Keep Your Eye On The Ball And Swing!

Build this page, or copy and paste it into your PHP editor, and save it as formprocess.php. Take a minute to look the code over before continuing with your reading.

<HTML><HEAD><TITLE>PHP Form Basics</TITLE></HEAD><BODY><center><?php//This is a simple form processor//validate the page_title variableIf (!$page_title){ echo "No Page Title Assigned<br>";}else{ echo "page_title: ".$page_title."<br>";}//validate the log-in informationIf(!$username){ echo "No User Name Entered<br>";}else{ If($username=="Midnight"){ If(!$password){ echo "No Password Entered<br>"; }else{ If($password=="mypass"){ echo "You have logged into the system!<br>"; }else{ echo "Invalid Password Entered<br>"; } } }else{ echo "Invalid User Name Entered<br>"; } }?></center></FORM></BODY></HTML>

The code above, while not exactly as elegant as I would like it to be, clearly demonstrates a simple but effective login algorithm. You will notice that I use negative logic throughout the code. This simply means I test to see if the page_title variable does not exist with the If(!$page_title) as opposed to assuming that the page_title variable exists. I use negative logic a great deal when I code, but this is a personal preference and not necessarily how you should develop your personal coding style. Each person is different, and while computer science courses are designed to churn out happy little algorithm automatons, it is important to never let go of the artistic and creative passions that led you to programming in the first place.

Running The Bases

Upload these files and point your browser at the first HTML form that we built. You should see the makings of a simple authentication system for your website project. You will notice that the username and password are hard-coded into the formprocess.php page. Our next article will begin to delve into the world of interacting with a Relational Database Management System (RDBMS), namely MYSQL.

Until the next time, keep coding and don’t give up. Remember, it’s hard to hit a home run unless you keep stepping up to the plate to take your turn at bat.

— Midnight

Bob Cristello is a recognized leader in the programming world. His articles on programming have appeared in Byte, InfoWorld, Avatar, Computer Telephony and Visual Basic Programmers Journal. He is a former keynote speaker for the Microsoft nationwide broadcast series. Bob’s clients have included Prodigy Online, Arthur Anderson and Nellie Mae. He recently retired as the Head of the Internet Development Group at REBAR and lives just outside of Boston with his wife, Elsibeth. Most days, Bob and Elsibeth can be found in irc.webmasterlive.com in #adultnetsurprise and are better known as Midnight and Kandi. Bob can be reached by emailing midnighterotica@hotmail.com or via ICQ# 118997859.

  • google-share
Previous Story

A Webmaster’s First-Time Adventure at Internext Vegas

Next Story

Revolutionary gallery generation

Leave a Reply Cancel reply

You must be logged in to post a comment.

Sponsor

YNOT Shoot Me

YNOTShootMe.com has exclusive pics from adult industry business events. Check it out!

YNOT Directory

  • Erotic Trade Only
    News & Resources
  • Adult Male Content
    Adult Content Brokers
  • Christie’s Sales
    Novelty & Lingerie Distributors
  • Premiere Listing

    Clickadu – Your trusted traffic souce

    More Details

RECENT

POPULAR

COMMENTS

Birthday Girl Chloe Amour Named Evil Angel of the Month

Posted On 09 May 2025

Mindi Mink and Black Label Magazine Present: Taboo Temptations Episode Three

Posted On 09 May 2025
MojoHost to Roll Out Powerful New GPU Servers

MojoHost Rolling Out Powerful New GPU Servers

Posted On 09 May 2025

Vanessa, Meet Vivid

Posted On 29 Sep 2014
Laila Mickelwaite and Exodus Cry

Laila Mickelwaite, Exodus Cry and their Crusade Against Porn

Posted On 03 May 2021

Sex Toy Collective Dildo Sculptor

Posted On 19 Mar 2019

Find a good sex toy is now a problem,...

Posted On 18 Mar 2024

Thanks to the variety of sex toys, I can...

Posted On 02 Feb 2024

I understand the concerns about...

Posted On 05 Jan 2024

Sponsor

Sitemap
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkPrivacy Policy