• Log in or sign up for an account here: https://www.sythe.org/login

PHP - [Tutorial] #2 - Webforms and PHP

speedster239

Forum Addict

Java Programmers
Joined
Jan 21, 2007
Sythe Gold
0
Messages
313
Location
Arkansas
Difficulty: Extremely Easy

Almost everyday you'll fill out a webform written in html. You might not know it but when you press the "accept" button their is usually a php script being executed!

Today were going to learn how to program a simple webform where you'll enter your name and the variable will be passed to a php script in which it will be output using the "echo" function!

Step 1:

We going to create a simple webform as below...

Code:
<form action="output.php" method="post">
Name: <input type="text" name="name"><br>
<input type="Submit">
</form>

As you can see above this will create a simple form with and input bogs and a submit button. At the top where it says ( <form action="output.php" method="post"> ) this is defining that when the submit button of the form is pressed the output.php script will be executed!

Step 2:

Now that we've created the webform we will now create the output.php file!

Code:
<?
$name=$_POST['name'];
echo "$name";
?>


The above script is very simple. It gets the post "variables" from the form we created. The variable, as defined in the form is 'name'. It gets the text value the user enters and turns it into the $name variable. Note, all variables in php are started with a "$" sign!

The third line has the php script output the value of the name variable!

Step 3:

Upload these files to your webserver, run the form and it should work!

Congratulations...
 
once again nice tut and i will be looking for another one, could a mod mabey ask for a php, or weblang forum?
 
i am very pleased to here that, good luck with you tuts and hopefully you will get a user ed rank one day
 
This is good tutorial too...
 
Runescape Gamblingrunescape gambling
Back
Top