PHP教程

表单PHP

本文主要是介绍表单PHP,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

图片;
在这里插入图片描述

代码:

<!DOCTYPE html>
<html>
<head>
	<title></title>
		<style type="text/css">
		.register{
			width: 400px;
			margin: 0 auto;
			background-color: #abe;
			padding: 20px;
		}
		.register>h2{
			text-align: center;
			color: #f22;
		}
	</style>
</head>

<body>
	<div class="register">
	<h2>用户注册</h2>
<!-- action 属性 只代表目标文件   method属性有两个值默认 
提交方式:get(适用于数据量比较小),
另一个:post(提交到文件请求符,适用规范数据量较大,更安全) -->
		<form action="zy3.2.php?y=100" method="post">
		<fieldset>
		<legend>必须填写</legend>
		<div>
		<label for="username" >用户名:</label>
		<input id="username" type="text" name="username" placeholder="用户名不少于四个字符" autofocus
		required="" >
		</div>
		<div>
		<label for="password" >密 码:</label>
		<input id="password" type="password" name="password" placeholder="请输入密码" required="" >
		</div>
		<div>
		<label for="email" >邮 箱:</label>
		<input id="email" type="email" name="email" placeholder="请输入邮箱" >
		</div>
		</fieldset>
		<div>
			<label for="" >性 别:</label>
			<input id="male" type="radio" name="male" value="男" >
			<label for="male">男</label>

			<input id="remale" type="radio" name="male" value="女" >
			<label for="remale">女</label>

			<input id="baomi" type="radio" name="male" checked value="保密" />
		     <label for="">保密</label>

		</div>
		
		<div>
			<label for="">爱好体育项目</label>
			<input type="checkbox" name="hobby[]" value="篮球">
			<label for="basketball">篮球</label>

			<input type="checkbox" name="hobby[]" value="足球">
			<label for="football">足球</label>

			<input type="checkbox" name="hobby[]" value="游泳">
			<label for="swim">游泳</label>
		</div>
		<div>
		<label for="">专业</label>
			<select name="department" id="">
			<option >请选择专业</option>
			<option >软件技术</option>
			<option >计算机应用</option>
			<option >计算机信息管理</option>
			</select>
		</div>
		<div>
			<textarea name="intruduce" id="cols" rows="4" cols="6"></textarea>
		</div>

		
		<button style="margin: 0 0 0 100px">提交</button>
	</form>
	</div>

</body>


</html>	


<?php 
$username=$_REQUEST['username'];
$pwd=$_POST['password']??"";
$email=$_POST['email']??"";
$male=$_POST['male'];
$hobby=$_POST['hobby'];
$department=$_POST['department'];
$intruduce=$_POST['intruduce'];

echo "用户名:".$username;
echo "<br>";
echo "密 码:$pwd";
echo "<br>";
echo "邮 箱:$email";
echo "<br>";
echo "性 别:$male";
echo "<br>";
echo "爱好:";
print_r($hobby);
echo "<br>";
echo "专业:";
echo $department;
echo "<br>";
echo "多行框:";
echo $intruduce;

 ?>

这篇关于表单PHP的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!