我在下面的处理表格中遇到错误。我不确定为什么当我点击提交时它没有更新到数据库。它说已经成功了,但是数据库还没有更新吗?!
我认为可能是因为“ mysqli_stmt_execute”,但是我不确定。 有什么想法吗 :/ 谢谢。
<?php
if(isset($_POST['submit'])){
include_once 'connection.php';
$first = mysqli_real_escape_string($conn, $_POST['first']);
$last = mysqli_real_escape_string($conn, $_POST['last']);
$uid = mysqli_real_escape_string($conn, $_POST['uid']);
$pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
$hashedPwd = md5($pwd);
//Error Handling
//Checking for empty fields
if(empty($first) || empty($last) || empty($uid) || empty($pwd)){
header("Location: ../signup.php?signup=empty");
exit();
}else{
//Checking if the input characters are valid
if(!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last) ){
header("Location: ../signup.php?signup=invalid");
exit();
}else{
$sql = "SELECT * FROM users WHERE Staff_ID='$uid'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if($resultCheck > 0){
header("Location: ../signup.php?signup=usertaken");
exit();
}else{
//Hasing the password surecirty
}
}
}
//Insert user into database
$sql = "INSERT INTO users (Firstname, Lastname, Staff_ID, Password) VALUES (?, ?, ?, ?);";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)){
echo"SQL Error";
} else{
mysqli_stmt_bind_param($stmt, "ssss", $first, $last, $uid, $pwd);
mysqli_stmt_execute($stmt);
}
header("Location: ../signup.php?signup=success");
exit();
}else{
header("Location: ../signup.php");
exit();
}
?>