Home | Login | Register | user control panel | view your posts |
question
FAQ
news
News
feedback
Feedback
HTML CSS PHP SQL
View unread posts | View new posts | View active posts
Login | Register | Search:
PHP GET and POST
user
forum by: user: admin, Post on: 2021-12-14 14:26:39, Posts: 129

php get and post

user: admin / Posts: 43 / post on: 2022-01-12 20:54:10
user
php get and post

The GET Method

The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? character.

<?php
if( $_GET["name"] || $_GET["age"] ) {
echo "Welcome ". $_GET['name']. "<br />";
echo "You are ". $_GET['age']. " years old.";

exit();
}
?>
<html>
<body>

<form action = "<?php $_PHP_SELF ?>" method = "GET">
<p> Name: <input type = "text" name = "name" /></p>
<p> Age: <input type = "text" name = "age" /></p>
<input type = "submit" />
</form>

</body>
</html>

 

user: admin / Posts: 44 / post on: 2022-01-12 20:54:27
user
php get and post

The POST Method

The POST method transfers information via HTTP headers. The information is encoded as described in case of GET method and put into a header called QUERY_STRING.

<?php
if( $_POST["name"] || $_POST["age"] ) {
if (preg_match("/[^A-Za-z'-]/",$_POST['name'] )) {
die ("invalid name and name should be alpha");
}
echo "Welcome ". $_POST['name']. "<br />";
echo "You are ". $_POST['age']. " years old.";

exit();
}
?>
<html>
<body>

<form action = "<?php $_PHP_SELF ?>" method = "POST">
<p> Name: <input type = "text" name = "name" /></p>
<p>Age: <input type = "text" name = "age" /></p>
<input type = "submit" />
</form>

</body>
</html>

Post User for this topic: title
Please Login to replay: Login | Register