| | |
Setting up a form in PHP
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2003
Posts: 1
Reputation:
Solved Threads: 0
I am a new student to php and I am working on my first project. I have created an html form, a php output form and a php confirm form. I am having trouble linking them together, when I fill in the information on my form it does not show up in the output form or confirm form.. Any tips or suggestions on what I should do or check?
Thanks,
Joe
Thanks,
Joe
•
•
•
•
Originally Posted by deef
I am a new student to php and I am working on my first project. I have created an html form, a php output form and a php confirm form. I am having trouble linking them together, when I fill in the information on my form it does not show up in the output form or confirm form.. Any tips or suggestions on what I should do or check?
Thanks,
Joe

<--- runs looking for those night vision goggles
Your basic HTML form is going to have the following:
my example is a quick & dirty login script
Page1.html
Your next page (login.php) will need have the following attributes.
You have 2 variables submitted from the form on the previous page. The variables are $user_id & $user_pass.
Your PHP script now needs to do something with these variables. You can compare the username and password to something stored in your PHP file. (not very secure), or later once you are working with a MySQL database, you can locate the corresponding user's information, and either accept the users login, and redirect them to a members page, or deny the login, and print an error.
In short, your HTML form is going to send variables to the PHP script. When you declare a "name=" on an input field, that variable is sent to the next page with that variable name. Then you have to do something with it. Print it out, manipulate the database with it, etc.
Let me do a little more simple example so you can see just what I mean.
This example will just print out some of the information that a user submits, and nothing else.
Now, my next page is going to use the information they submitted, and print it back on the screen.
confirm.php
[php]
// Since we aren't doing anything fancy, the only PHP function
// I'm using here is echo
echo "
Hello, $first_name $last_name,
Thanks for signing up for our newsletter.
I show that your email address is $email_address.
We will be sending your the first copy soon!!! Thanks!
";
[/php]
Note:
Your variables that you've submitted from the HTML form appear simply as $first_name, $last_name, and $email_address. This method of retrieving the variables is not secure.
Someone could type in yourwebsite.com/confirm.php?first_name=Joe&last_name=Flipper&email=
well you get the idea. This can cause problems if you are sending hidden variables to the next page like a user_id, etc.
To avoid this, and the newly adopted way to call varaibles is via an array created by the PHP server automatically.
The same variables above can be obtained by using
$_POST[first_name], $_POST[last_name], and $_POST[email_address].
this guarantees that the values for these items was only submitted to the script using the POST method. If you are taking classes, or reading up to date info, they should ONLY recommend using this option. I learned on the standard variable and have had to switch over to adopt the newer, safer way of retrieving these variables.
Hope this helps a bit, or might point you in the right direction.
my example is a quick & dirty login script
Page1.html
PHP Syntax (Toggle Plain Text)
<form method=POST action=login.php> <input type=text name=user_id> <input type=password name=user_pass> <input type=submit value=Login> </form>
Your next page (login.php) will need have the following attributes.
You have 2 variables submitted from the form on the previous page. The variables are $user_id & $user_pass.
Your PHP script now needs to do something with these variables. You can compare the username and password to something stored in your PHP file. (not very secure), or later once you are working with a MySQL database, you can locate the corresponding user's information, and either accept the users login, and redirect them to a members page, or deny the login, and print an error.
In short, your HTML form is going to send variables to the PHP script. When you declare a "name=" on an input field, that variable is sent to the next page with that variable name. Then you have to do something with it. Print it out, manipulate the database with it, etc.
Let me do a little more simple example so you can see just what I mean.
This example will just print out some of the information that a user submits, and nothing else.
PHP Syntax (Toggle Plain Text)
<form method=POST action=page.php> Enter your first name: <input type=text name=first_name><br /> Enter your last name: <input type=text name=last_name><br /> Enter your email address: <input type=text name=email_address><br /> <input type=submit value=Login> </form>
Now, my next page is going to use the information they submitted, and print it back on the screen.
confirm.php
[php]
// Since we aren't doing anything fancy, the only PHP function
// I'm using here is echo
echo "
Hello, $first_name $last_name,
Thanks for signing up for our newsletter.
I show that your email address is $email_address.
We will be sending your the first copy soon!!! Thanks!
";
[/php]
Note:
Your variables that you've submitted from the HTML form appear simply as $first_name, $last_name, and $email_address. This method of retrieving the variables is not secure.
Someone could type in yourwebsite.com/confirm.php?first_name=Joe&last_name=Flipper&email=
well you get the idea. This can cause problems if you are sending hidden variables to the next page like a user_id, etc.
To avoid this, and the newly adopted way to call varaibles is via an array created by the PHP server automatically.
The same variables above can be obtained by using
$_POST[first_name], $_POST[last_name], and $_POST[email_address].
this guarantees that the values for these items was only submitted to the script using the POST method. If you are taking classes, or reading up to date info, they should ONLY recommend using this option. I learned on the standard variable and have had to switch over to adopt the newer, safer way of retrieving these variables.
Hope this helps a bit, or might point you in the right direction.
•
•
Join Date: Jan 2008
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
I am a new student to php and I am working on my first project. I have created an html form, a php output form and a php confirm form. I am having trouble linking them together, when I fill in the information on my form it does not show up in the output form or confirm form.. Any tips or suggestions on what I should do or check?
Thanks,
Joe
![]() |
Similar Threads
- Insert HMTL Code into MySQL Database through a Form with PHP (MySQL)
- Need Contact Us form using PHP Script (PHP)
- 'Tell a friend' form for my PHP script (Web Development Job Offers)
- displaying a form within a php script (PHP)
- Setting Form Controls Dynamically... (C#)
Other Threads in the PHP Forum
- Previous Thread: google map question
- Next Thread: change f5 keyCode to <input type='file'>
| Thread Tools | Search this Thread |
5.2.10 ajax apache api array basic beginner binary broken cakephp checkbox class cms code computing confirm cron curl database date delete display domain dynamic echo email error fatalerror file files folder form forms function functions google href htaccess html iframe image include indentedsubcategory insert interactive ip javascript joomla limit link load login mail malfunction menu mlm msqli_multi_query multiple mysql mysqlquery navigation oop paging parse paypal pdf php procedure query radio ram random reference remote return script search server sessions sockets source space sql syntax system table thesishelp tutorial unset update upload url validation validator variable video web websitecontactform xml youtube





