本示例中创建了两个表单,一个表示使用GET方式提交,一个表单使用POST方式提交,然后在服务器端通过$_GET['submitted']和$_POST['submitted']来判断是哪个表单被提交了,最后将提交的数据显示给用户浏览器上。具体代码如下所示:
<html>
</head>
<body>
<?php
if ($_GET[\'submitted\'] == \"yes\"){
if (trim ($_GET[\'yourname\']) != \"\"){
echo \"Your Name (with GET): \" . $_GET[\'yourname\'];
} else {
echo \"You must submit a value.\";
}
?><br /><a href=\"index.php\">Try Again</a><?php
}
if ($_POST[\'submitted\'] == \"yes\"){
if (trim ($_POST[\'yourname\']) != \"\"){
echo \"Your Name (with POST): \" . $_POST[\'yourname\'];
} else {
echo \"You must submit a value.\";
}
?><br /><a href=\"index.php\">Try Again</a><?php
}
?>
<?php
if ($_GET[\'submitted\'] != \"yes\" && $_POST[\'submitted\'] != \"yes\"){
?>
<form action=\"index.php\" method=\"get\">
<p>GET Example:</p>
<input type=\"hidden\" name=\"submitted\" value=\"yes\" />
Your Name: <input type=\"text\" name=\"yourname\" maxlength=\"150\" /><br />
<input type=\"submit\" value=\"Submit with GET\"/>
</form>
<form action=\"index.php\" method=\"post\">
<p>POST Example:</p>
<input type=\"hidden\" name=\"submitted\" value=\"yes\" />
Your Name: <input type=\"text\" name=\"yourname\" maxlength=\"150\" /><br />
<input type=\"submit\" value=\"Submit with POST\"/>
</form>
<?php
}
?>
</body>
</html> 继续阅读与本文标签相同的文章
下一篇 :
可视化编程已经能取代高级语言了吗?
-
超进化,时尚玩主的全新一代名爵ZS,起步只要7.98万
2026-05-14栏目: 教程
-
微信 7.0.8 内测新功能,教你如何激活它
2026-05-14栏目: 教程
-
美女机器人刚上市就售罄,除了生孩子,其他什么都能干!
2026-05-14栏目: 教程
-
互联网之光大会的黑科技,总有一款惊艳你!
2026-05-14栏目: 教程
-
微信宣布一项新举措,关系到每一个用户,网友一致力挺:干得漂亮!
2026-05-14栏目: 教程
