我有一个创建新帐户页面。表单位于名为Register.php的页面中,一旦用户提交,它将转到Confirm.php,如果一切正确,它将验证字段,显示“帐户创建”消息。
在Chrome中。错误消息显示在Register.php中,一次全部显示 填充字段然后只显示confirm.php。但在Mozilla中,它 转到Confirm.php并显示一个空白页面。
我的Register.php代码是:
<div class="signup_form">
<form action="confirm.php" method="post" >
<?php
session_start();
if(isset($_SESSION['error']))
{
echo '<p>'.$_SESSION['error']['username'].'</p>';
echo '<p>'.$_SESSION['error']['email'].'</p>';
echo '<p>'.$_SESSION['error']['password'].'</p>';
unset($_SESSION['error']);
}
?>
<p>
<font size="3" face="arial" color="gray"> <label for="username"><b> UserName*</b> </label> </font>
<input name="username" type="text" id="username" input style="height:33px" size = "50" size="30"/>
</p>
<p>
<font size="3" face="arial" color="gray"> <label for="email"><b> E-mail Address*</b> </label> </font>
<input name="email" type="text" id="email" input style="height:33px" size = "50" size="30"/>
</p>
<p>
<font size="3" face="arial" color="gray"> <label for="password"><b> Password*</b> </label> </font>
<input name="password" type="password" id="password" input style="height:33px" size = "50" size="30"/>
</p>
<p>
<input name="submit" type="image" src="images/submit.gif" value="submit"/> </p>
</form>
</div>
并且对于Confirm.php代码是:
<?php
session_start();
include('configdb.php');
if(isset($_POST['submit']))
{
if($_POST['username'] == '')
{
$_SESSION['error']['username'] = "User Name is required.";
}
if($_POST['email'] == '')
{
$_SESSION['error']['email'] = "E-mail is required.";
}
else
{
if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['email']))
{
$email= $_POST['email'];
$sql1 = "SELECT * FROM user WHERE email = '$email'";
$result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error($mysqli));
if (mysqli_num_rows($result1) > 0) {
$_SESSION['error']['email'] = "This Email is already used.";
}
}
else
{
$_SESSION['error']['email'] = "Your email is not valid.";
}
}
if($_POST['password'] == '')
{
$_SESSION['error']['password'] = "Password is required.";
}
if(isset($_SESSION['error']))
{
header("Location: register.php");
exit;
}
else
{
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$sql2 = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$password')";
$result2 = mysqli_query($mysqli,$sql2) or die(mysqli_error());
if($result2)
{
echo '<div>Your account is now active. You may now <a href="login.php">Log in</a></div>';
}
}
} ?>
答案 0 :(得分:2)
将if(isset($_POST['submit']))
与input type="image"
结合使用无法正常工作,因为浏览器应发送submit.x
和submit.y
以及点击图片的坐标。
相反,请尝试使用if($_POST)
确保表单已提交,或者isset($_POST['username'])
或其他您知道名称的字段。