Seiya Tanaka Subject: Internet and Web Development
Seiya Tanaka Subject: Internet and Web Development
Seiya Tanaka Subject: Internet and Web Development
Seiya Tanaka
Subject:
Internet and Web Development
Contents
Functions
Form
POST
GET
Functions
Besides the built-in PHP functions, we can
create our own functions.
<?php
function writeMsg() {
echo "Hello world!";
}
<?php
function familyName($fname) {
echo "$fname<br>";
}
familyName("Jani");
familyName("Hege");
familyName("Stale");
familyName("Kai Jim");
familyName("Borge");
?>
Returning values
To let a function return a value, use the
return statement:
<?php
function sum($x, $y) {
$z = $x + $y;
return $z;
}
</body>
</html>
Form(POST)
To display the submitted data you could
simply echo all the variables. The
"welcome.php" looks like this:
welcome.php
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo
$_POST["email"]; ?>
</body>
</html>
Form(GET)
The same result could also be achieved using
the HTTP GET method:
index.html
<html>
<body>
</body>
</html>
Form(GET)
and "welcome_get.php" looks like this:
welcome_get.php
<html>
<body>
Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo
$_GET["email"]; ?>
</body>
</html>
When to use
GET or POST?
GET
POST
Functions
Form
POST
GET
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: