Home > Backend Development > PHP Tutorial > PHP implementation of obtaining form data and HTML embedded PHP script

PHP implementation of obtaining form data and HTML embedded PHP script

墨辰丷
Release: 2023-03-28 06:06:02
Original
1534 people have browsed it

This article mainly introduces the PHP implementation of obtaining form data and HTML embedding PHP scripts. Interested friends can refer to it. I hope it will be helpful to everyone.

When PHP accepts information submitted through an HTML form, it will save the submitted data in a global array. We can call the system-specific automatic global variable array to obtain these values.

Commonly used automatic global variables are as follows:

1. GET method

Function: Get the data submitted by get method

Format: $_GET["formelement"]

2. POST method

Function: Get the data submitted by post method

Format: $_POST["formelement"]

##3. REQUEST method

Function: Get data submitted in any way. The $_REQUEST automatic global variable contains all GET, POST, COOKIE and FILE data, if you don’t care about the data source.

Format: $_REQUEST["formelement"]

Check box, list box (the name is in the form of an array For example: "select[]", just use $_POST["select"] when getting its value)

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>
<!--获取表单数据的两种方法-->
<!--post-->
<form method="post" action="8.3.php" name="form1">
 <table border="1" width="400" cellpadding="0" cellspacing="0">
 <tr>
  <td height="30"> 用户名:<input name="txtName" type="text" size="12">
  密码:<input name="txtPsd" type="password" size="12">
  <input type="submit" name="SubmitBtn" value="提交">
  </td>
 </tr>
 </table>
</form><br/>

<!--get URL的长度需要限定在1M范围内,否则会截取-->
<!--可以使用urlencode与urldecode对URL进行编解码-->
<form method="get" action="8.3.php" name="form2">
 <table border="1" width="400" cellpadding="0" cellspacing="0">
 <tr>
  <td width="400" height="30"> 订单号:<input name="txtFrame" type="text" size="12">
  <input type="submit" name="SubmitBtn">
  </td>
 </tr>
 </table>
</form>

<!--在Web页面中嵌入PHP脚本-->
<?php
  $strTxt = &#39;男&#39;;
?>
<input type="text" value="<?php echo "strTxt"; ?>">

</body>

<?php
  echo &#39;用户名: &#39;.$_POST["txtName"]." 密码:".$_POST[&#39;txtPsd&#39;];
  echo &#39;订单号:&#39;.$_GET["txtFrame"];
?>

</html>
Copy after login

The above is the entire article Content, I hope it will be helpful to everyone’s study.


Related recommendations:

AJAX submissionForm dataExample analysis

PHP Post cannot obtain non- form dataHow to handle

##PHP

Form dataCode to write to MySQL database

The above is the detailed content of PHP implementation of obtaining form data and HTML embedded PHP script. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template