用表单结果重定向PHP表单


PHP Form to redirect with form results

我有一个表单,当他们提交它时,它会将信息存储在数据库中。我需要能够得到的表单数据出现在重定向页面上。

它不需要获取数据库,因为我喜欢这种PHP风格。让我们假设他们进入那里的名字和城市。当他们点击提交时,它会将他们重定向到一个感谢页面,其中包含该页面上表单的结果。

在表单中,每个元素都有一个名称,比如name="username",在php中,根据表单的method,您可以将其值作为getpost响应。

HTML表单

<form action="process.php" method="get">
    <input name="username" type="text"></input>
    <input type="submit" value="Submit"></input>
</form>

<form action="process.php" method="post">
    <input name="username" type="text"></input>
    <input type="submit" value="Submit"></input>
</form>

process.php

$someusername = $_GET['username'];
$someusername = $_POST['username'];

表单页面:

<form action="thanks.php" method="post"><input type="text" name="myname" placeholder="Name" /><input type="text" name="mycity" placeholder="City" /><input type="submit" value="submit"></form>

PHP页面

print "Thanks, ".$_POST['myname']." who lives in ".$_POST['mycity']."!";