我正在尝试创建一个注册表单。让它在我的localhost(XAMPP)中成功执行后,我将其上传到网络服务器(000webhost)。但是当我运行该文件时,浏览器给了我500个http错误。
我试图调试代码,并发现php文件在我的PDO bindParam()函数中停止执行
$prep_stmt = $conn->prepare("INSERT INTO `user` (`UserID`, `Username`, `Password`, `FullName`, `Role`, `Gender`, `Age`, `DoB`, `Email`, `Phonenumber` , `RegDate`, `Intro`, `E_isVerified`, `TrustPoint`) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?, 0, 0);");
$prep_stmt->bind_Param("sssiiisssss", $reg_user, $reg_password, $reg_fullname, $reg_role, $reg_gender, $reg_age, $date, $reg_email, $reg_phone, $reg_date, $reg_desc);
它在bind_Param函数()之后没有执行任何其他行,并返回HTTP ERROR 500
这是我的完整代码
<?php
function validateTime($date, $format = 'Y-m-d'){
$d = DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
}
require('connect.php');
$prep_stmt = $conn->prepare("INSERT INTO `user` (`UserID`, `Username`, `Password`, `FullName`, `Role`, `Gender`, `Age`, `DoB`, `Email`, `Phonenumber` , `RegDate`, `Intro`, `E_isVerified`, `TrustPoint`) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?, 0, 0);");
$prep_stmt->bind_Param("sssiiisssss", $reg_user, $reg_password, $reg_fullname, $reg_role, $reg_gender, $reg_age, $date, $reg_email, $reg_phone, $reg_date, $reg_desc);
$token = "";
$reg_age = 10; //Remember to add it later
$reg_user = $_POST['username'];
$reg_user = mysqli_real_escape_string($conn, $reg_user);
$reg_password = $_POST['password'];
$reg_password = mysqli_real_escape_string($conn, $reg_password);
$reg_fullname = $_POST['name'];
$reg_fullname = mysqli_real_escape_string($conn, $reg_fullname);
$reg_cfpassword = $_POST['cf_password'];
$reg_cfpassword = mysqli_real_escape_string($conn, $reg_cfpassword);
$reg_phone = $_POST['phonenumber'];
$reg_phone = mysqli_real_escape_string($conn, $reg_phone);
$reg_email = $_POST['email'];
$reg_email = mysqli_real_escape_string($conn, $reg_email);
$day = $_POST['dd'];
$day = mysqli_real_escape_string($conn, $day);
$month = $_POST['mm'];
$month = mysqli_real_escape_string($conn, $month);
$year = $_POST['yyyy'];
$year = mysqli_real_escape_string($conn, $year);
$reg_gender = $_POST['gender'];
$reg_gender = mysqli_real_escape_string($conn, $reg_gender);
$reg_country = $_POST['country'];
$reg_country = mysqli_real_escape_string($conn, $reg_country);
$reg_city = $_POST['city'];
$reg_city = mysqli_real_escape_string($conn, $reg_city);
$reg_address = $_POST['address'];
$reg_address = mysqli_real_escape_string($conn, $reg_address);
$reg_role = $_POST['role'];
$reg_role = mysqli_real_escape_string($conn, $reg_role);
$reg_brandname = $_POST['brandname'];
$reg_brandname = mysqli_real_escape_string($conn, $reg_brandname);
$reg_job = $_POST['job'];
$reg_job = mysqli_real_escape_string($conn, $reg_job);
$reg_desc = $_POST['description'];
$reb_desc = mysqli_real_escape_string($conn, $reg_desc);
$reg_agree = $_POST['agree'];
$reg_agree = mysqli_real_escape_string($conn, $reg_agree);
$reg_date = date("Y-m-d");
$reg_date = mysqli_real_escape_string($conn, $reg_date);
//Check
$name_check = "/^.{1,100}$/";
$password_check = "/^.{1,100}$/"; //Check if password == confirm
if ($reg_password != $reg_cfpassword){
header("Location: register.php?err=1");
exit;
}
$phonenumber_check = "/^[0]{1}[0-9]{9,10}$/";
$username_check = "/^[0-9a-zA-Z]{3,50}$/"; //Unique
//Date check
$date = $year.'-'.$month.'-'.$day;
// echo $date;
// if (!validateTime($date)) $token.="&date=1";
if (!preg_match($name_check, $reg_fullname)) $token.="&name=1";
if (!preg_match($password_check,$reg_password)) $token.="&pw=1";
if (!preg_match($phonenumber_check, $reg_phone)) $token.="&phone=1";
if (!preg_match($username_check, $reg_user)) $token.="&usr=1";
$querycheck = "SELECT Username FROM user WHERE Username='$reg_user'";
$res = $conn->query($querycheck);
if ($res->num_rows > 0){
$token.="&usr_dup=1";
}
if ($token == "" && $prep_stmt->execute()){
$track_id_query = "SELECT `UserID`,`Username`,`Password` FROM `user` WHERE Username = '$reg_user'";
$track_id_result = mysqli_query($conn, $track_id_query);
if ($row = mysqli_fetch_array($track_id_result,MYSQLI_ASSOC)) {
session_start();
$cookie_username = 'username';
$cookie_id = 'id';
$cookie_password = 'password';
$username = $row['Username'];
$password = $row['Password'];
$id = $row['UserID'];
// set cookies
setcookie($cookie_username, $username, time() + (86400 * 30), "/"); // 86400 = 1 day
setcookie($cookie_id, $id, time() + (86400 * 30), "/"); // 86400 = 1 day
setcookie($cookie_password, $password, time() + (86400 * 30), "/");
$_SESSION['id'] = $id;
$prep_stmt->close();
$path = "images/users/".$id;
mkdir($path, 0700);
fopen($path."/avatar.png","w");
copy('images/blank.jpgo',$path."/avatar.jpg");
header('Location: account.php');
exit;
}
}
else {
// die(mysqli_error($conn));
header('Location: register.php?'.$token);
exit;
}
// die(mysqli_error($conn));
$conn->close();
?>