我想在用户点击提交按钮时将页面重定向到网站。如果所有字段都为空,则显示错误“请填写所有字段”;否则,它应该重定向到网站。
这是我的代码:
<?php
include "dbConfig.php";
$msg = '';
if(!empty($_POST)) {
if(($_POST[ 'email' ]!="") && ($_POST[ 'password' ]!="") ) {
$email = $_POST["email"];
$password = $_POST["password"];
$sql = "insert into members set email='".$email."', password='".$password."'";
$sql = $link->query($sql);
$msg = '<p class = "tanx">Thank you for completing your online registration form!.';
}
else {
$msg = '<div class="pam login_error_box uiBoxRed">
<div class="fsl fwb fcb">Incorrect Email</div>
<div><p>The email you entered does not belong to any account.</p><p>You can login using any email, username or mobile phone number associated with your account. Make sure that it is typed correctly.</p>
</div></div>';
}
}
?>
答案 0 :(得分:0)
试试这个......
另外我可能会注意到,如果您使用此当前代码并且用户未输入电子邮件或密码,则会告诉他们他们的电子邮件不属于某个帐户。在他们输入有效电子邮件但输入密码错误的情况下,这是没有意义的。
我建议您考虑稍微修改一下代码。
<?php
include "dbConfig.php";
$msg = '';
if(!empty($_POST)) {
if(($_POST[ 'email' ]!="") && ($_POST[ 'password' ]!="") ) {
$email = $_POST["email"];
$password = $_POST["password"];
$sql = "insert into members set email='".$email."', password='".$password."'";
$sql = $link->query($sql);
$msg = '<p class = "tanx">Thank you for completing your online registration form!.';
}
else {
$msg = '<div class="pam login_error_box uiBoxRed">
<div class="fsl fwb fcb">Incorrect Email</div>
<div><p>The email you entered does not belong to any account.</p><p>You can login using any email, username or mobile phone number associated with your account. Make sure that it is typed correctly.</p>
</div></div>';
}
} else {
header('Location: failed.php');
}
?>