我需要此表單的操作來調用我的腳本,然後如果電子郵件地址已經在數據庫中,它應該顯示警報。提交後保留字段值
這個工程,但很明顯,我被指向我的空白腳本頁面,當我回到表單時,數據已經消失。
我希望被重定向到數據完整的窗體並顯示警報。
我已經嘗試了整天,讓會議工作,現在我只是困惑。
如果有人能告訴我什麼以及爲每個頁面添加會話代碼的位置,我會非常感激。
本頁面握住我的形式:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'></script>
<script src='http://ajax.microsoft.com/ajax/jquery.validate/1.7/additional-methods.js'></script>
<script src='http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js'></script>
<script src="../js/register_validate.js" type="text/javascript"></script>
<link href="../css/styles.css" rel="stylesheet" type="text/css">
<base target="_top">
</head>
<body>
<p><?php include ('register_form2.php') ?></p>
</body>
</html>
這是包含表單頁面:
<form action="register_script2.php" method="POST" name="form_register" id="form_registerID" accept-charset="UTF-8">
<aside class="field_reg_form">
<input name="field_email1" type="text" required id="field_email1ID" /><br /><br />
<input name="field_email2" type="text" required id="field_email2ID" /><br /><br />
<input type="submit" value="submit" id="submit" name="submit" />
</aside>
</form>
下面是PHP腳本:
<?php
require_once('../scripts/connect.php');
$con = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME) or die('Could not connect to database server.');
if(isset($_POST['submit'])) {
$var_Email1 = mysqli_real_escape_string($con, $_POST['field_email1']);
$var_Email2 = mysqli_real_escape_string($con, $_POST['field_email2']);
if ($var_Email1 == $var_Email2){
$sql = mysqli_query($con, "SELECT * FROM membership WHERE Email = '$var_Email1' ");
if(mysqli_num_rows($sql) > 0){
print '<script type="text/javascript">';
print 'alert("The email address '. $_POST['field_email1'].' is already in our database")';
print '</script>';
exit();
}
echo "not in database";
}
}
?>
非常好!這正是我需要的。非常感謝!! – Lori 2014-11-03 01:26:15
@Lori很高興這有幫助 – Ghost 2014-11-03 01:28:12