PHP获取表单数据与HTML嵌入PHP脚本的实现

yipeiwu_com5年前PHP代码库

 php接受通过HTML表单提交的信息时,会将提交的数据保存在全局数组中,我们可以调用系统特定的自动全局变量数组来获取这些值。

常用的自动全局变量如下所示:

1、GET方式

功能:获取get方式提交的数据

格式:$_GET[“formelement”]

2、POST方式

功能:获取post方式提交的数据

格式:$_POST[“formelement”]

3、REQUEST方式

功能:获取任意方式提交的数据,$_REQUEST自动全局变量包含了所有GET、POST、COOKIE和FILE的数据,如不关心数据来源。

格式:$_REQUEST[“formelement”]

复选框 、列表框(名称采用数组形式如:"select[]",在获取其值的时候直接使用$_POST["select"]即可)

<!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 = '男';
?>
<input type="text" value="<?php echo "strTxt"; ?>">

</body>

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

</html>

以上这篇PHP获取表单数据与HTML嵌入PHP脚本的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【宜配屋www.yipeiwu.com】。

相关文章

简单谈谈favicon

简单谈谈favicon

favicon.ico介绍 favicon.ico是个什么东西呢,也许见得太多都习以为常了(我就是这样,直到写这篇文章之前才知道),看看维基百科的解释: 复制代码 代码如下: Favic...

php cli 方式 在crotab中运行解决

复制代码 代码如下: /var/www/html/bt/e/BtSys:.:/usr/share/pear:/usr/share/phpPHP Warning: require(../c...

php中fsockopen用法实例

本文实例讲述了php中fsockopen用法。分享给大家供大家参考。 具体实现方法如下: 复制代码 代码如下:$fp=fsockopen("127.0.0.1",80); &n...

如何在PHP中使用正则表达式进行查找替换

1. preg_match — 执行一个正则表达式匹配int preg_match ( string $pattern , string $subject [, array &$matc...

php print EOF实现方法

我写段php代码如下: 复制代码 代码如下:<? if(test case) print<<<EOT <....html code....> EOF;...