web开发n例
案例3:使用post和get方法在php和html间传递参数
case3.php:
<!DOCTYPE html>
<html>
<head>
<!-- 请将文档保存为UTF-8编码,否则中文会乱码 -->
<meta charset="UTF-8">
<title>案例3</title><!-- 使用post和get方法在php和html间传递参数 -->
</head>
<body>
<!-- 使用get方法传递 -->
<form action="case3-output.php" method="get">
get提交的数据:<input type="text" name="getText">
<input type="hidden" name="getHidText" value="get隐藏文字">
<input type="submit" name="g_sb"><!--提交按钮,只有提交了才能够传递表单参数-->
</form>
<!-- 通过url直接传递,也属于get方法 -->
<a href="case3-output.php?urlText=传递文字">点击超链接传递参数</a>
<!-- 使用post方法传递 -->
<form action="case3-output.php" method="post">
post提交的数据:<input type="text" name="postText" >
<input type="hidden" name="postHidText" value="post隐藏文字">
<input type="submit" name="p_sb"><!--提交按钮,只有提交了才能够传递表单参数-->
</form>
</body>
</html><?php
if(isset($_GET["getText"]))
echo "get传递的数据为:{$_GET['getText']}<br>";
else
echo "没有通过get传递数据<br>";
if(isset($_GET["getHidText"]))
echo "get传递的隐藏数据为:{$_GET['getHidText']}<br>";
else
echo "没有通过get传递隐藏数据<br>";
if(isset($_GET["urlText"]))
echo "url传递的数据为:{$_GET['urlText']}<br>";
else
echo "没有通过url传递数据<br>";
if(isset($_POST["postText"]))
echo "post传递的数据为:{$_POST['postText']}<br>";
else
echo "没有通过post传递数据<br>";
if(isset($_POST["postHidText"]))
echo "post传递的隐藏数据为:{$_POST['postHidText']}<br>";
else
echo "没有通过post传递隐藏数据<br>";以上就介绍了web开发N例-案例3:使用post和get方法在php和html间传递参数,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号