//, PHP/Create and Use a User Input Form

Create and Use a User Input Form

Create and Use a User Input Form

So how do you access the information you submitted via HTML in the script (script.php)?  Well amazingly, there are several ways to get the information.  It’s up to you to decide which method best suites you, and then go with that.  When you submit a form to a script, a certain set of variables are automatically created for you.

http://www.website.com/script.php" method="post">
Form 1: <input type="text" name="form1"><BR>
Form 2: <input type="text" name="form2"><BR>

<input type="submit" value="submit">


Let’s now pretend I submitted that form with information via the "post" method filling in "form1" with "hi" and "form2" with "bye".  To see this visually, I’ll show you how it would look via the "get" method:


Remember that the only differences between the "post" and "get" methods are:
-"post" doesn’t cache information, while "get" does
-the "get" method is limited in the amount of information you can send while the "post" method is not

The first way to access the information is via the "superglobals" PHP provides.  "Superglobals" are variables that can be accessed anywhere in the script regardless of scope (we’ll learn about this later when we get to functions).  The "superglobals" are 9 special associated arrays which hold ALL the information you input into a script.  Here they are:

$_SERVER – these are variables set by the server

$_GET – this is information you send via the "get" method into your script

$_POST – this is information you send via the "post" method into your script

$_COOKIE – this arrays holds all cookie information your computer sends to the script

$_FILES – when you upload files in PHP, they are held inside this array

$_ENV – the environmental variables

$_REQUEST – a combination of all user-input to your script

$_SESSION – much like cookies, these are session variables which hold information for you

I will be concentrating almost all the examples on the "post" and "get" methods because they are the easiest to follow.  There are equivalent older versions of the above which are not "superglobals" and only exist in the global scope (again we’ll get into this when we discuss functions).  Here are the "superglobals" and their old deprecated counterparts (remember again that these are associated arrays):

$_REQUEST – new, didn’t exist before

By now you should be totally confused, and I completely understand if you are, because I haven’t explained a thing about how to use these arrays.  Let’s take out "get" method example:


Here is how I would access the "form1" and "form2" information is submitted inside the script:

http://www.website.com/script.php?name1=Jeff&name2=Joseph (remember, this means you either typed this directly inside your address bar in your browser, or that you submitted forms with names "name1" and "name2" via HTML with the "get" method).

2010-05-26T10:52:42+00:00 June 20th, 2005|HTML, PHP|0 Comments

About the Author:

Darren Hedlund is a freelance Web developer, writer, and data analyst. Darren has a degree in Computer Information Science and has spent the last 15 years developing application and environments from hand held, windows, web, virtual science, gaming, artificial intelligence and graphics design.

Darren's coding knowledge ranges from C+, Visual Basic, .NET, PHP, JSP, REXX, KIXX, and many others. His graphical and environmental knowledge stems in Macromedia Flash, 3D studio Max, Curious Labs Poser, Adobe Photoshop, and many others. Darren works in many platforms ranging from database, visual design, and, system development.

Leave A Comment