我是 php 和 javascript 的新手。我在第一个 php 文件中编写了一个模式对话框打开脚本,用于创建新用户帐户。在模式窗口中输入有效输入后,我通过 post 方法将信息发送到第二个 php 页面以插入数据库中的数据。
现在有问题了。在第二个 php 页面中,有一种方法可以检查数据库中是否已经存在电子邮件地址,然后显示错误,否则将数据插入数据库并重定向到第三个 php 页面。
但无法编写相同的逻辑。请指导我编写逻辑,如果在第 2 页中电子邮件检查方法返回 true,然后在成功插入数据重定向到第 3 页后显示错误 else。
请在下面找到代码片段
2nd php 和 3rd php 在同一个文件夹中。head() 部分不起作用,还需要显示错误以进行第二页验证。第一个 php 大部分代码是 javascript 和 html form.from 那里我正在发布到第二页
**1st php**
<script>
$("#dialog-form").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Create an account": function() {
var bValid = true;
allFields.removeClass("ui-state-error");
bValid = bValid && checkLength(email, "email", 6, 80);
bValid = bValid && checkLength(password, "password", 5, 16);
bValid = bValid && checkLength(confirmpassword, "confirmpassword", 3, 16);
bValid = bValid && checkRegexp(email, .....);
bValid = bValid && checkRegexp(password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9");
bValid = bValid && IsEqual(password, confirmpassword, "password & confirmpassword are not equal");
if (bValid) {
$.ajax({
type: "POST",
url: "./create_account.php?act=create",
data: "&email=" + email.val() + "&password=" + password.val() + "&confirmpassword=" + confirmpassword.val(),
success: function(data) {
}
});
$(this).dialog("close");
}
},
Cancel: function() {
$(this).dialog("close");
}
},
close: function() {
allFields.val("").removeClass("ui-state-error");
}
});
$("#create-user")
.button()
.click(function() {
$("#dialog-form").dialog("open");
});
});
</script>
<div id="dialog-form" title="Create new user">
<p class="validateTips">All form fields are required.</p>
<form>
<fieldset>
<label for="email">Email</label>
<input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
<label for="password">Password</label>
<input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" />
<label for="confirmpassword">confirm password</label>
<input type="password" name="confirmpassword" id="confirmpassword" class="text ui-widget-content ui-corner-all" />
</fieldset>
</form>
</div>
**2nd php**
<?php
$action = $_GET['act'];
if(!empty($_POST['email'])&&($_POST['password'])&&($_POST['confirmpassword'])) {
$email_address = tep_db_prepare_input($HTTP_POST_VARS['email']);
$password = tep_db_prepare_input($HTTP_POST_VARS['password']);
$confirmpassword = tep_db_prepare_input($HTTP_POST_VARS['confirmpassword']);
$error = false;
{
$db = new mysql("root", "", "modal_db", "localhost");
$email_query_status ="select count(*) as total from " . CUSTOMERS . " where customers_email_address = $email_address ;
$check_email = mysql($email_query_status );
if ($check_email['total'] > 0) {
$error = true;
}
}
if ($error == false) {
$db->query("INSERT INTO user_info SET customers_email_address ='$email_address', password='$pword'");
header('Location: 3rd.php');
}
}
?>
Thanks in advance,
Debasis