PHP - 调用自己的表单动作,如何在1页中显示所有内容? [英] PHP - form action calling itself, how to display everything in 1 page?
本文介绍了PHP - 调用自己的表单动作,如何在1页中显示所有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
test1.php
< HTML>
< head>
< title>样本< / title>
< / head>
< body>
< form action =test2.phpmethod =post>
请输入一个数字< input type =numbername =userNumber>< br>
< input type =submit>
< / form>
< / body>
< / html>
test2.php
< HTML>
< head>
< title>示例显示页面< /标题>
< / head>
< body>
<?php
$ user_number = $ _POST [userNumber];
echo您已选择$ user_number;
?>
< / body>
< / html>
我想知道如何才能将它全部显示在单个页面上,即在test1上.php,而不必拥有两个文件。
解决方案
您的 test1.php
将需要看起来像这样
< html>
< head>
< title>样本< / title>
< / head>
< body>
< form action =test1.phpmethod =post>
请输入一个数字< input type =numbername =userNumber>< br>
< input type =submit>
< / form>
<?php
if(isset($ _ POST [userNumber])){
$ user_number = $ _POST [userNumber];
echo您已选择$ user_number;
}
?>
< / body>
< / html>
I have two .php files as such:
test1.php
<html>
<head>
<title>Sample</title>
</head>
<body>
<form action="test2.php" method="post">
Please enter a number <input type="number" name="userNumber"><br>
<input type="submit">
</form>
</body>
</html>
test2.php
<html>
<head>
<title>Sample Display Page</title>
</head>
<body>
<?php
$user_number = $_POST["userNumber"];
echo "You have chosen $user_number";
?>
</body>
</html>
I want to know how can I get it all to display on a single page, i.e. on the test1.php, without having to have two files.
解决方案
Your test1.php
will need to look like this
<html>
<head>
<title>Sample</title>
</head>
<body>
<form action="test1.php" method="post">
Please enter a number <input type="number" name="userNumber"><br>
<input type="submit">
</form>
<?php
if(isset($_POST["userNumber"])) {
$user_number = $_POST["userNumber"];
echo "You have chosen $user_number";
}
?>
</body>
</html>
这篇关于PHP - 调用自己的表单动作,如何在1页中显示所有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文