Thanks to visit codestin.com
Credit goes to www.slideshare.net

AIMS AND OBJECTIVES
Web Server Scripting
• Create a form in PHP
• Transfer data to another page using PHP
Web Server Scripting
Server Side Languages
PHP RECAP
<? php
Code
?>
Web Server Scripting
Server Side Languages
PHP RECAP
Variables
$x = 0; // sets up a variable
Web Server Scripting
Server Side Languages
Creating a form:
You do this in normal HTML code (but
still save it as a PHP page). Look at the
handout sheet for the form.
Web Server Scripting
Server Side Languages
When you submit the form:
<form method="post" action="result.php">
The server looks for result.php
All the text boxes full of information are
turned into php variables
Web Server Scripting
Server Side Languages
On result .php…
For example the text box called
first_name
Becomes $_POST['first_name'];
You can then use that variable.
Web Server Scripting
Server Side Languages
$first_name = $_POST['first_name'];
Stores the first_name in a semi-
permanent variable called $first_name.
You can then “echo” it or store it.
Web Server Scripting
Server Side Languages
On result.php
Echo $first_name.”<br>”;
Web Server Scripting
Server Side Languages
PHP – Forms
Passing Variables from a Form:
Welcome <?php echo $first_name; ?>!<br />
You are <?php echo $age; ?> years old.
Web Server Scripting
Server Side Languages
Use the handout to create form.php
And result.php which shows what has
been entered into the form.
Save in public_html
View at
Web Server Scripting
Extension:
Try using method=“GET” instead of
Method=“POST”
What is the difference?

Web server scripting - Using a form

  • 1.
    AIMS AND OBJECTIVES WebServer Scripting • Create a form in PHP • Transfer data to another page using PHP
  • 2.
    Web Server Scripting ServerSide Languages PHP RECAP <? php Code ?>
  • 3.
    Web Server Scripting ServerSide Languages PHP RECAP Variables $x = 0; // sets up a variable
  • 4.
    Web Server Scripting ServerSide Languages Creating a form: You do this in normal HTML code (but still save it as a PHP page). Look at the handout sheet for the form.
  • 5.
    Web Server Scripting ServerSide Languages When you submit the form: <form method="post" action="result.php"> The server looks for result.php All the text boxes full of information are turned into php variables
  • 6.
    Web Server Scripting ServerSide Languages On result .php… For example the text box called first_name Becomes $_POST['first_name']; You can then use that variable.
  • 7.
    Web Server Scripting ServerSide Languages $first_name = $_POST['first_name']; Stores the first_name in a semi- permanent variable called $first_name. You can then “echo” it or store it.
  • 8.
    Web Server Scripting ServerSide Languages On result.php Echo $first_name.”<br>”;
  • 9.
    Web Server Scripting ServerSide Languages PHP – Forms Passing Variables from a Form: Welcome <?php echo $first_name; ?>!<br /> You are <?php echo $age; ?> years old.
  • 10.
    Web Server Scripting ServerSide Languages Use the handout to create form.php And result.php which shows what has been entered into the form. Save in public_html View at
  • 11.
    Web Server Scripting Extension: Tryusing method=“GET” instead of Method=“POST” What is the difference?