我正在向个人PHP项目添加注册功能,但是在将数据插入MySQL数据库时,它会将姓氏记录为数组而不是字符串。数据库中的列显示单词“ Array”而不是真实名称,并且echo mysqli_info($conn);
返回“ Array in string conversion in...。”是否有解决方法?还是我做错了什么?
数据库结构 Database Structure
表格 enter image description here
数据库结果 enter image description here
HTML
<form action="includes/signup-handler.php" method="post" class="signup-form">
<div class="form-group">
<input type="text" name="firstName" id="firstName" class="form-control" placeholder="first name">
</div>
<div class="form-group">
<input type="text" name="lastName" id="lastName" class="form-control" placeholder="last name">
</div>
<div class="form-group">
<input type="email" name="email" id="email" class="form-control" placeholder="email address">
</div>
<div class="form-group">
<input type="password" name="password" id="password" class="form-control" placeholder="password">
</div>
<div class="form-group">
<input type="password" name="repeatPassword" id="password" class="form-control" placeholder="confirm password">
</div>
<button type="submit" class="btn btn-success" name="submit">Sign up</button>
</form>
还有PHP处理程序;
if(isset($_POST['submit'])){
require 'connection.php';
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
//Check for validation
} elseif(!filter_var($email, FILTER_VALIDATE_EMAIL) && filter_var($email, FILTER_SANITIZE_EMAIL)){
header("Location: ../register.php?error=invalidemail");
exit();
}
elseif (!preg_match("/^[a-zA-Z0-9]*$/", $firstName, $lastName)) {
header("Location: ../register.php?error=invalidname&email=".$email);
exit();
}
//Create prepared statements for validation
else {
$selectQuery = "SELECT * FROM users WHERE email=?";
$statement = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($statement, $selectQuery)){
header("Location: ../register.php?error=sqlerror");
exit();
}else{
mysqli_stmt_bind_param($statement, "s", $email);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
$resultCheck = mysqli_stmt_num_rows($statement);
if ($resultCheck > 0) {
header("Location: ../register.php?error=usertaken&firstName=".$firstName."&lastName=".$lastName."&email=".$email);
exit();
}else{
$insertQuery = "INSERT INTO users (firstName, lastName, email) VALUES (?, ?, ?);";
$statement = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($statement, $insertQuery)){
header("Location: ../register.php?error=sqlerror");
exit();
}else {
mysqli_stmt_bind_param($statement, 'sss', $firstName, $lastName , $email);
mysqli_stmt_execute($statement);
header("Location: ../register.php?error=success");
//echo mysqli_info($conn);
// var_dump($lastName);
exit();
}
}
}
}
mysqli_stmt_close($statement);
mysqli_close($conn);
}else{
header("Location: ../register.php");
exit();
}