943,901 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 7553
  • PHP RSS
Oct 27th, 2003
0

Setting up a form in PHP

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
deef is offline Offline
1 posts
since Oct 2003
Nov 10th, 2003
0

Re: PHP help!

Quote 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
Give some code dear, so we can tell where the problem exactly lies instead of firing the dart in the dark

<--- runs looking for those night vision goggles
Reputation Points: 46
Solved Threads: 1
Junior Poster in Training
jayant is offline Offline
95 posts
since Nov 2003
Nov 15th, 2003
0

Re: PHP help!

Your basic HTML form is going to have the following:

my example is a quick & dirty login script

Page1.html
PHP Syntax (Toggle Plain Text)
  1. <form method=POST action=login.php>
  2. <input type=text name=user_id>
  3. <input type=password name=user_pass>
  4. <input type=submit value=Login>
  5. </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)
  1. <form method=POST action=page.php>
  2. Enter your first name: <input type=text name=first_name><br />
  3. Enter your last name: <input type=text name=last_name><br />
  4. Enter your email address: <input type=text name=email_address><br />
  5. <input type=submit value=Login>
  6. </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.
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
himerus is offline Offline
82 posts
since Aug 2003
Jan 9th, 2008
0

Re: Setting up a form in PHP

Click to Expand / Collapse  Quote 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
I am also having the same problem PHP is not working in my system is there any one who can solve my problem .
Reputation Points: 10
Solved Threads: 0
Newbie Poster
adilz.cool is offline Offline
5 posts
since Jan 2008
Jan 9th, 2008
0

Re: Setting up a form in PHP

go to w3schools.com , this will help you
Reputation Points: 5
Solved Threads: 5
Junior Poster
vssp is offline Offline
197 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: google map question
Next Thread in PHP Forum Timeline: change f5 keyCode to <input type='file'>





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC