search
Homephp教程php手册实例详解PHP如何获取表单数据

这篇文章主要介绍了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;];
  }
?>

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值
  }
?>

注意输出的内容为表单的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]."       ";
   }
?>

【相关教程推荐】

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

2. php从入门到精通  

3. bootstrap教程 

Statement
This article is reproduced at:CSDN博客. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!