Home > php教程 > php手册 > body text

实例详解PHP如何获取表单数据

WBOY
Release: 2018-10-26 17:12:54
forward
857 people have browsed it

这篇文章主要介绍了PHP如何获取表单数据,有一定的参考价值,感兴趣的朋友可以看看,希望对你有帮助!

<form name="form1" method="post" action="">
	<table width="509" border="0">
		<tr>
			<td> 用户名:</td>
			<td><input type="text" name="user" size="20"></td><!--name相当于是数组名-->
			<td> 密  码:</td>
			<td><input name="pwd" type="password" id="pwd" size="20"></td><!--id相当于是数组名-->
			<td><input name="submit" type="submit" id="submit" value="登陆"/></td>
		</tr>
	</table>
</form>
<?php
  if(isset($_POST["submit"])&&$_POST["submit"]=="登陆"){
	  echo "您输入的用户名为:".$_POST["user"]."  l;密码为:".$_POST[&#39;pwd&#39;];
  }
?>
Copy after login

1).

2).name为表单名   method为表单提交的方式    action为处理该表单页面的URL

3).为行对齐   为列对齐

4).则为表单中的输入域标记

5).name则为文本框的名字(类似于数组中的索引) type为输入域的类型

6).isset($_POST["submit"] 检测变量是否被设置 判断POST中的数据是否被提交过来

7).$_POST["submit"]=="登陆"   判断提交的按钮是否为登陆  

<form name="form1" method="post" action="">
    性别;
    <input name ="sex" type="radio" value="男" checked>男
	<input name ="sex" type="radio" value="女" >女
	<input name="Submit" type="submit" value="提交" >
</form>
<?php
  if(isset($_POST["sex"])&&$_POST["sex"]!=""){
	  echo "您选择的性别为:".$_POST["sex"];//输出的内容为表单的value值
  }
?>
Copy after login

注意输出的内容为表单的value值

<form name="form1" method = "post" action="">
	<table width="540" cellpadding="0" cellspacing="0">
		<tr>
			<td width="400" height="25" align="center" valign="top">
				您喜欢的类型:
				<input type="checkbox" name="mrbook[]" value="入门类">
				入门类
				<input type="checkbox" name="mrbook[]" value="案例类">
				案例类
				<input type="checkbox" name="mrbook[]" value="讲解类">
				讲解类
				<input type="checkbox" name="mrbook[]" value="实力类">
				实力类
			</td>
			<td width="40" align="center" valign="top">
				<input type="submit" name="submit" value="提交">
			</td>
		</tr>
	</table>
</form>
<?php
   if(isset($_POST[&#39;mrbook&#39;])&&$_POST[&#39;mrbook&#39;]!=null){ //判断复选框 不为空执行下面操作 
	  echo "you choose        "; //多个空格多个 
	  for($i = 0;$i<count($_POST[&#39;mrbook&#39;]);$i++)
		  echo $_POST[&#39;mrbook&#39;][$i]."       ";
   }
?>
Copy after login

【相关教程推荐】

1. php编程从入门到精通全套视频教程 

2. php从入门到精通  

3. bootstrap教程 

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