我有一个将信息发送到 mysql 数据库的表单。错误消息和确认显示在表单右侧的单独 div 中,因此表单操作需要将用户发送到同一页面。我正在回显用户输入的字段,以防他们需要根据出现的错误消息编辑某些内容。但是,如果表单提交正确,我怎样才能使 php 不在表单中回显?
<?php
$submit = filter_input(INPUT_POST, 'submit');
//form data
$fullname = filter_input(INPUT_POST, 'fullname');
$email = filter_input(INPUT_POST, 'email');
$business = filter_input(INPUT_POST, 'business');
$date = date("Y-m-d");
?>
然后在其他html代码之后....
<div class="wrap">
<div id="reg">
<form action='register.php' method='POST'>
<table>
<tr>
<td>
Your full name:
</td>
<td>
<input type='text' name='fullname' value='<?php echo $fullname;?>'>
}
</td>
</tr>
<tr>
<td>
Your email:
</td>
<td>
<input type='text' name='email' value='<?php echo $email;?>'>
</td>
</tr>
<tr>
<td>
Your business:
</td>
<td>
<input type='text' name='business' value='<?php echo $business;?>'>
</td>
</tr>
</table>
</br>
<input type='submit' name='submit' value='Register'>
</form>
</br>
</div>
<?php
if ($submit)
{
//open database
$connect=mysql_connect("localhost","root","Ryweb1994");
mysql_select_db("phapsy");
//check for existence
if($fullname&&$business&&$business)
{
$queryreg = mysql_query("INSERT INTO users VALUES ('','$fullname','$email','$business','$date')");
echo ("<div id='message'><p>You have been registered! We will send you an email with login information. Thank you for your interest in Phapsy!<p></div>");
}
else echo "Please fill in <b>all</b> fields!";
}
?>
</div>
</div>