【发布时间】:2020-01-04 05:11:51
【问题描述】:
我创建了一个 html 注册表单(signup.php)。我将dbf/signup.dbf.php 作为操作页面放在dbf 文件夹中。以下代码属于signup.dbf.php。“dbc.dbf.php”是提供数据库连接的脚本。
<?
if(isset($_POST['createbtn'])){
require 'dbc.dbf.php';
$uid=$_POST['uid'];
$mail=$_POST['email'];
$pwd=$_POST['pw'];
$repwd=$_POST['re-pw'];
$add=$_POST['address'];
if(empty($uid)||empty($mail)||empty($pwd)||empty($add)||empty($repwd))
{
header("Location: ../signup.php?error=emptyfields&uid=".$uid."&email=".$mail);
exit();
}
else if(!filter_var($mail,FILTER_VALIDATE_EMAIL)&&!preg_match("/[a-zA-Z0-9]$/",$uid)){
header("Location:../signup.php?error=invalidemailuid");
exit();
}
else if(!filter_var($mail,FILTER_VALIDATE_EMAIL)&&!preg_match("/[a-zA-Z0-9]$/",$uid)){
header("Location:../signup.php?error=invalidemailuid");
exit();
}
else if(!filter_var($mail,FILTER_VALIDATE_EMAIL)){
header("Location:../signup.php?error=inavalidemail&uid=".$uid);
exit();
}
else if(!preg_match("/[a-zA-Z0-9]$/",$uid)){
header("Location:../signup.php?error=inavalideuid&email=".$mail);
exit();
}
else if($pwd!=$repwd){
header("Location:../signup.php?error=passwordcheck&uid=".$uid."&email=".$mail);
exit();
}
else{
$sql="SELECT uid FROM user_details WHERE uid=?";
$stmnt=mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmnt,$sql)){
header("Location:../signup.php?error=sqlerror");
exit();
}
else{
mysqli_stmt_bind_param($stmnt,"s",$uid);
mysqli_stmt_execute($stmnt);
mysqli_stmt_store_result($stmnt);
$results=mysqli_stmt_num_rows($stmnt);
if($results>0){
header("Location:../signup.php?error=usertaken&email".$mail);
exit();
}
else{
$sql="INSERT INTO user_details(uid,email,password,address) VALUES(?,?,?,?)";
$stmnt=mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmnt,$sql)){
header("Location:../signup.php?error=sqlerror");
exit();
}
else{
$hashpwd=password_hash($pwd,PASSWORD_DEFAULT);
mysqli_stmt_bind_param($stmnt,"ssss",$uid,$mail,$hashpwd,$add);
mysqli_stmt_execute($stmnt);
header("Location:../index.php");
exit();
}
}
}
}
mysqli_stmt_close($stmnt);
mysqli_close($conn);
}
else{
header("Location:../signup.php");
}
但是当我单击注册表单的createbtn 时,它既不会将数据保存在数据库中,也不会将页面重定向到signup.php。它总是卡在 signup.dbf.php 显示以下代码。
0){
header("Location:../signup.php?error=usertaken&email".$mail);
exit();
}
else{
$sql="INSERT INTO user_details(uid,email,password,address) VALUES(?,?,?,?)";
$stmnt=mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmnt,$sql)){
header("Location:../signup.php?error=sqlerror");
exit();
}
else{
$hashpwd=password_hash($pwd,PASSWORD_DEFAULT);
mysqli_stmt_bind_param($stmnt,"ssss",$uid,$mail,$hashpwd,$add);
mysqli_stmt_execute($stmnt);
header("Location:../index.php");
exit();
}
}
}
}
mysqli_stmt_close($stmnt);
mysqli_close($conn);
}else{header("Location:../signup.php");
exit();}
即使我评论了这段代码,它仍然会显示。谁能帮我解决这个问题?
【问题讨论】: