3
<?php
if(isset($_POST['submit'])) 
{ 
    $name = $_POST['name'];
    echo "User Has submitted the form and entered this name : <b> $name </b>";

}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
   <input type="text" name="name"><br>
   <input type="submit" name="submit" value="Submit Form"><br>
</form>

我只希望在提交后运行部分并在单击提交表单按钮后不应该看到显示表单

4

2 回答 2

6

在 else 部分中编写您的 html 表单代码。

<?php
if(isset($_POST['submit'])) 
{ 
    $name = $_POST['name'];
    echo "User Has submitted the form and entered this name : <b> $name </b>";

} else {
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
   <input type="text" name="name"><br>
   <input type="submit" name="submit" value="Submit Form"><br>
</form>

<?php } ?>
于 2013-01-22T05:09:09.533 回答
1

使用退出

if(isset($_POST['submit']) {
    $name = $_POST['name'];

    echo "User has submitted the form and entered this name : <b> $name </b>";

    exit;
}
于 2013-01-22T05:09:18.823 回答