我有一个弹出式注册表单,注册效果很好,但是如果用户输入无效的电子邮件并提交表单,那么当用户再次打开它或刷新页面时,只会出现错误,表示错误消息有效,但不正常时间或者我不知道发生了什么。
这是我的PHP注册码:
<?php
if (isset($_POST['submit'])) {
$password = md5($_POST["password"]);
$link = mysqli_connect("localhost","root","mysql");
mysqli_select_db($link,"myuser");
$count = 0;
$res = mysqli_query($link,"select * from register where email='$_POST[email]'") ;
$count = mysqli_num_rows($res);
if ($count>0) {
$emailErr = "Email already exists";
}
else{
mysqli_query($link,"insert into register values('','$_POST[username]' ,'$_POST[email]' ,'$password')");
header("location:index.php");
}
}
?>
这是我的html弹出窗体代码:
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
<div class="modal2">
<div class="modal2_close close2"></div>
<div class="modal2_main">
<div class="login-screen">
<div class="app-title">
<h1>Sign Up</h1>
</div>
<div><img src="images/common.png" class="circle"></div>
<div class="login-form">
<div class="control-group">
<input type="text" class="login-field" value="" placeholder="username" name="username" required pattern="^[A-Za-z0-9]+">
<label class="login-field-icon fui-user" for="login-name"></label>
</div>
<div class="control-group2">
<input type="text" class="login-field" value="" placeholder="Email" name="email" required pattern="^[A-Za-z0-9]+">
<label class="login-field-icon fui-user" for="login-name"></label>
<span><?php echo $emailErr;?></span>
</div>
<div class="control-group">
<input type="password" class="login-field" value="" placeholder="password" name="password" required
pattern="^[A-Za-z0-9]+">
<label class="login-field-icon fui-lock" for="login-pass"></label>
</div>
<button name="submit" class="btn btn-primary btn-large btn-block">Register</button>
</div>
</div>
</div>
</div>
</form>
答案 0 :(得分:0)