表单处理 php 脚本无法正常工作



我创建了一个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();}

即使我注释了此代码,它也会继续显示。谁能帮我解决这个问题

您的 PHP 代码是否打印在浏览器输出上? 显然,当您没有将代码正确放入 PHP 标签中时,就会发生这种情况。你在代码上使用短的PHP标签(<?(,需要php.inishort_open_tag的许可。确保已设置此设置或使用默认的 PHP 标记。

最新更新