PHP-get和post请求

get请求: 

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>登录界面</title>
</head>
<body>
	<h1>登录界面</h1>
	<form action="check.php" method="get">
		用户名:<input type="text" name="username"><br>
		密码:<input type="password" name="password"><br>
		<input type="submit" value="提交">
	</from>
</body>
</html>

代码效果: 

 输入内容,通过$_GET[],参数在URL后面,多个参数用&进行连接。

 

post请求

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>登录界面</title>
</head>
<body>
	<h1>登录界面</h1>
	<form action="check.php" method="post">
		用户名:<input type="text" name="username"><br>
		密码:<input type="password" name="password"><br>
		<input type="submit" value="提交">
	</from>
</body>
</html>

通过$_POST[] ,参数在请求体中,如下图:

 

 举例:PHP获取学生成绩案例

 result.php

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>学生成绩界面</title>
	<style>
		ul{
			list-style:none;<!--去掉每行前面的点-->
			color:red;
		}
		.title{
			font-size:20px;
		}
	</style>
</head>
<body>
<?php
	$data=array();
	$data["123"]=array("name"=>"张三","chinese"=>"103","math"=>"89","english"=>"143");
	$data["234"]=array("name"=>"李四","chinese"=>"123","math"=>"69","english"=>"43");
	$data["345"]=array("name"=>"王五","chinese"=>"83","math"=>"129","english"=>"63");
	$code=$_GET["code"]; 
?>
	<?php
		if(array_key_exists($code,$data)){
			$result=$data[$code];
	?> 
	<div>
		<div class="title"><?php echo $result["name"] ?>成绩如下</div>
		<ul>
			<li>语文:<?php echo $result["chinese"] ?></li>
			<li>数学:<?php echo $result["math"] ?></li>
			<li>英语:<?php echo $result["english"] ?></li>
		</ul>
	</div>
	<?php
	}else{
	?>
		<div>该学生考号不存在</div>
		<?php } ?>
</body> 
</html>

 Login.html

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>查询学生的成绩</title>
</head>
<body>
	<h1>请在下列输入框中输入学生的考号进行查询:</h1>
	<form action="result.php" method="get">
		输入考号:<input type="text" name="code"><br> 
		<input type="submit" value="查询">
	</from>
</body>
</html>

 

 

 

 POST方式

 

发布了102 篇原创文章 · 获赞 17 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/Ciel_Y/article/details/104431293