Home  >  Article  >  Backend Development  >  A brief discussion on PHP form submission, a brief discussion on form form_PHP tutorial

A brief discussion on PHP form submission, a brief discussion on form form_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:47:58780browse

A brief discussion on php submission of form forms, a brief discussion on form forms

Processing GET requests

The function implemented is to display "Hello XXX" on the page after entering the name

Create html file hello.html:

<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title>欢迎</title>
</head>
<body>
<form action="hello.php" method="get">
  <input name="name" type="text"/>
  <input type="submit"/>
</form>
</body>
</html>

Create PHP file hello.php:

<&#63;php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/6/30
 * Time: 15:03
 */
header("Content-type: text/html; charset=utf-8");
if(isset($_GET['name'])&&$_GET['name']){//如果有值且不为空
  echo 'Hello '.$_GET['name'];
}else{
  echo 'Please input name';
}

The Get request explicitly places the form data in the URI, and has restrictions on the length and data value encoding, such as: http://127.0.0.1/hello.php?name=Vito

Handling POST requests

Implement a simple addition function

Create html file add.html:

<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title>相加</title>
</head>
<body>
<form action="add.php" method="post">
  <input name="num1" type="text"/>
  +
  <input name="num2" type="text"/>
  <input type="submit" value="相加"/>
</form>
</body>
</html>

Create PHP file add.php:

<&#63;php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/6/30
 * Time: 18:02
 */


if($_POST['num1']&&$_POST['num2']){
  echo $_POST['num1']+$_POST['num2'];
}else{
  echo 'Please input num';
}

Post request puts the form data in the http request body, and there is no length limit

form action="" means: form is the form, action is the redirection address, that is, where the form needs to be submitted

The above is the entire content of this article, I hope you all like it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1024921.htmlTechArticleA brief discussion on php submission of form forms, a brief discussion on the function of form form processing GET request is that after entering the name, the page displays " Hello XXX” Create html file hello.html: !DOCTYPE htmlhtmlhead lang="...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn