Php 如果使用标题将用户重定向到其他页面,如何使用“通知用户表单提交错误”
当用户提交表单时,表单信息被发布到一个php文件中,并且一旦使用header函数提交表单,php文件会立即将用户重定向到下一个网页。我已经使用HTML和Javascript对表单进行了验证,但是PHP在表单中进行了验证,以便识别通过Javascript和HTML的任何错误并通知用户,但是这在一分钟内是不可能的,因为用户在收到通知之前会被重定向 如果PHP发现错误,我将如何识别用户? 是否有必要,因为只有那些故意恶意的人才会犯错误 我的代码是:Php 如果使用标题将用户重定向到其他页面,如何使用“通知用户表单提交错误”,php,html,forms,Php,Html,Forms,当用户提交表单时,表单信息被发布到一个php文件中,并且一旦使用header函数提交表单,php文件会立即将用户重定向到下一个网页。我已经使用HTML和Javascript对表单进行了验证,但是PHP在表单中进行了验证,以便识别通过Javascript和HTML的任何错误并通知用户,但是这在一分钟内是不可能的,因为用户在收到通知之前会被重定向 如果PHP发现错误,我将如何识别用户? 是否有必要,因为只有那些故意恶意的人才会犯错误 我的代码是: <?php 标题位置:下一个网页; ifi
<?php
标题位置:下一个网页;
ifisset$\u POST['submit']{
$data_missing = array();
if(empty($_POST['email_banned'])){
// Adds name to array
$data_missing[] = 'Email';
} else {
// Trim white space from the name and store the name
$email_banned = trim($_POST['email_banned']);
}
if(empty($_POST['notes'])){
// Adds name to array
$data_missing[] = 'Notes';
} else {
// Trim white space from the name and store the name
$notes = trim($_POST['notes']);
}
if(empty($data_missing)){
require_once('mysqli_connect.php');
$query = "INSERT INTO banned_emails (id, email_banned, created_on, notes) VALUES ( NULL, ?, NOW(), ?)";
$stmt = mysqli_prepare($dbc, $query);
//i Interger
//d Doubles
//s Everything Else
mysqli_stmt_bind_param($stmt, "ss", $email_banned, $notes);
mysqli_stmt_execute($stmt);
$affected_rows = mysqli_stmt_affected_rows($stmt);
if($affected_rows == 1){
echo 'Student Entered';
mysqli_stmt_close($stmt);
mysqli_close($dbc);
} else {
echo 'Error Occurred<br />';
echo mysqli_error();
mysqli_stmt_close($stmt);
mysqli_close($dbc);
}
} else {
echo 'You need to enter the following data<br />';
foreach($data_missing as $missing){
echo "$missing<br />";
}
}
}
?>
谢谢:您可以使用$\u会话存储错误,并在以后检索它们
$_SESSION['errors'] = array('an error message', 'a second error message');
然后在脚本中,用户被重定向到:
while($err = array_shift($_SESSION['errors'])){
?>
<p class='p_error'><?=$err?></p>
<?php
}
您的表单是否使用javascript进行验证?您能展示一些示例吗?我已经编辑了我的帖子,以包含代码。