如何在php中在同一页面上显示错误消息?
这是我的简单php表单脚本 当前,此脚本在下一页中显示所有错误,但我想在注册页中显示错误我如何才能做到这一点 我在学习php如何在php中在同一页面上显示错误消息?,php,forms,Php,Forms,这是我的简单php表单脚本 当前,此脚本在下一页中显示所有错误,但我想在注册页中显示错误我如何才能做到这一点 我在学习php <?php // i removed connection code due to mostly code error if (mysqli_connect_errno()) { exit('Failed to connect to MySQL: ' . mysqli_connect_error()); } if (empty($_POST['userna
<?php
// i removed connection code due to mostly code error
if (mysqli_connect_errno()) {
exit('Failed to connect to MySQL: ' . mysqli_connect_error());
}
if (empty($_POST['username']) || empty($_POST['account']) || empty($_POST['package']) || empty($_POST['Method']) || empty($_POST['TransactionId'])) {
exit('Please complete the registration form');
}
if ($stmt = $con->prepare('SELECT id, TransactionId FROM payment WHERE username = ?')) {
//i removed this code due to this error "It looks like your post is mostly code; please add some more details. if u want this plz let me know"
} else {
if ($stmt = $con->prepare('INSERT INTO payment (username, account, package, Method, TransactionId) VALUES (?, ?, ?, ?, ?)')) {
$stmt->bind_param('sssss', $_POST['username'], $_POST['account'], $_POST['package'], $_POST['Method'], $_POST['TransactionId']);
$stmt->execute();
echo 'You have successfully registered, you can now login!';
} else {
echo 'Could not prepare statement!';
}
}
$stmt->close();
} else {
echo 'Could not prepare statement!';
}
$con->close();
?>
要提交表单并在同一页面上显示结果而不重新加载,您需要使用Wesley is right,您需要在后台异步请求来处理PHP页面而不提交。这是用Javascript和AJAX完成的。但是php代码中的错误我如何用Javascript显示感谢您的回复
exit('Please complete the registration form');