The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > Web Programming > PHP


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Reply
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 06-10-2007, 03:47 PM
Lee's Avatar
Lee Lee is offline
PT Staff*
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: Blackpool, UK
Posts: 615
iTrader: (0)
Lee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enough
Simple form

Ok we are going to make a simple form that will display the information on the next page using the variables we have learnt about and the echo function.

first you need to make a document called index.htm, this is where the form will go, here is the code for the form:
HTML Code:
<html> <form method="post" action="index.php"> <p>Name:
    <input name="name" type="text"> </p> <p>Email:  
    <label> <input name="email" type="text"> </label> </p> <p> <label>Comment:<br> <textarea name="comment" cols="50" rows="6"></textarea> </label> </p> <p> <label> <input type="submit" name="Submit" value="Submit"> </label> </p> </form> </html>
I made this in dreamweaver to be quick but you can still do the same in any other text program.

You will notice that i have given everything a relevant name, this is important and you will notice why in the php code. Also you will see i have give the form an action, this action needs to be the file name of the .php file we are about to create, for this i have called it index.php

The php code:
PHP Code:
<?php 
$name 
$_REQUEST['name'];
$email $_REQUEST['email'];
$comment =  $_REQUEST['comment'];

echo 
"Hello $name, Your email is $email <br /><br />Your comment was:<br />$comment";


?>
Ok we know how the echo works and you will now see that when you use double quotes not only can you display the value of a variable but you can also use html inside it!

How the code works?
PHP Code:
$name $_REQUEST['name'];
$email $_REQUEST['email'];
$comment =  $_REQUEST['comment']; 
Here we have set the variables i will use the name variable as an example, i hope that you have noticed that the variable name has a request for the name box, the reason you have to request is to get the value of what has just been posted so the format is... $var_name = $_REQUEST['content']; ... content being the name of the textbox, options, combo boxes etc...

so now you know how to get the information into a variable all you have to do is print it on the page using the echo function:
PHP Code:
echo "Hello $name, Your email is $email <br /><br />Your comment was:<br />$comment"
You Should already know the echo function with variables from past tutorials so i am just mentioning it briefly, simply use double quotes so you can print variables and include some new breaks in the content to shove the comment down a couple of lines to make it look better.

Hope this has helped you, feel free to ask any questions.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 10:36 PM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50