本篇文章主要介绍php实现获取表单数据与html嵌入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>
以上就是本文的全部内容,希望对大家的学习有所帮助。
相关推荐:
ajax提交表单数据实例分析
php post获取不到非表单数据如何处理
php表单数据写入mysql数据库的代码
以上就是php实现获取表单数据与html嵌入php脚本的详细内容。
