先看示例代码:
<?php
$num_to_guess = 42;
$message = \"\";
if ( ! isset( $_POST[\'guess\'] ) ) {
$message = \"Welcome!\";
} else if ( $_POST[\'guess\'] > $num_to_guess ) {
$message = $_POST[\'guess\'].\" is too big!\";
} else if ( $_POST[\'guess\'] < $num_to_guess ) {
$message = $_POST[\'guess\'].\" is too small!\";
} else {
$message = \"Well done!\";
}
?>
<html>
<head>
< >php 表单提交给本页处理的实例</ >
</head>
<body>
<h1>
<?php print $message ?>
</h1>
<form method=\"post\" action=\"<?php print $_SERVER[\'PHP_SELF\']?>\">
<p>
Type your guess here: <input type=\"text\" name=\"guess\" />
<input type=\"submit\" value=\"submit\" />
</p>
</form>
</body>
</html>
可以看出,表单提交给本页处理与提交到其他页面处理的方法是一样的,这里需要注意几点:
- $_SERVER['PHP_SELF']表示获取当前页面的地址。
- 当表单的action值为空或没有设置的时候,表示表单是提交到本页的。
继续阅读与本文标签相同的文章
-
互联网之光大会的黑科技,总有一款惊艳你!
2026-05-14栏目: 教程
-
微信宣布一项新举措,关系到每一个用户,网友一致力挺:干得漂亮!
2026-05-14栏目: 教程
-
微软建议企业客户卸载KB4520062累积更新
2026-05-14栏目: 教程
-
他让我国芯片研究停滞13年,还骗走11亿研发资金,现状如何?
2026-05-14栏目: 教程
-
健乐教学机器人可开展的教学实训内容
2026-05-14栏目: 教程
