【发布时间】:2021-02-24 08:38:34
【问题描述】:
我查看了我的代码,但我不知道为什么这个错误不断出现。
我得到的确切错误信息 '解析错误:语法错误,第 92 行 C:\wamp\www\includes\functions.inc.php 中的文件意外结束'
这是我的代码:
<?php
#since this file contains solely PHP there is no need for the closing tag
#by convention it is better to check if something fails first then succeeds
function emptyInputSignup($username, $password, $passwordRepeat){
$result = Null;
if (empty($username) || empty($password) || empty($passwordRepeat)){
$result = true;
}
else{
$result = false;
}
return result;
}
function invalidUsername($username){
$result = Null;
#if there is a mistake
if (!preg_match("/^[a-zA-Z0-9]*$/", $username)){
$result = true;
}
else{
$result = false;
}
return result;
}
function passwordMatch($password, $passwordRepeat){
$result = Null;
#if there has been a mistake
if ($password !== $passwordRepeat){
$result = true;
}
else{
$result = false;
}
return result;
}
function usernameExists($conn, $username){
$sql = "SELECT * FROM users WHERE username = ?";
#we have created a prepared statement to prevent SQL injections
$stmt = mysqli_stmt_init($conn);
$result = Null;
if (!mysqli_stmt_prepare($stmt, $sql)){
header("location: ../signup.php?error=stmtfailed");
exit();
}
mysqli_stmt_bind_param($stmt, "s", $username);
mysqli_stmt_execute($stmt);
$resultData = mysqli_stmt_get_result();
if($row = mysqli_fetch_assoc($resultData)){
return $row;
}
else{
$result = false;
return $result;
}
function passwordValid($password){
$result = Null;
#if there is a mistake
if (strlen($password) <= 5 && !preg_match("~[0-9]+~", $password)){
$result = true;
}
else{
$result = false;
}
return result;
}
这是我认为错误所在的函数。
function createUser($conn, $username, $password){
$sql = "INSERT INTO users (username, password) VALUES (?, ?)";
#we have created a prepared statement to prevent SQL injections
$stmt = mysqli_stmt_init($conn);
#this checks if the statement is feasible
if (!mysqli_stmt_prepare($stmt, $sql)){
header("location: ../signup.php?error=stmtfailed");
exit();
}
#returns hash of a password
#this inbuilt function is constantly updated
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
mysqli_stmt_bind_param($stmt, "ss", $username, $hashedPassword);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
header("location: ../signup.php?error=none");
exit;
} #this is line 92 but I do not see where the issue is here
我已经对缺少括号和/或 php.ini 的状态如何导致此错误进行了一些研究,但是 short_open_tag 已设置为打开。 是什么导致了错误?
【问题讨论】:
-
算括号。另外,我看到还有一个错字,错误消息/警告如
undefined constant。 -
试试
usernameExists。 -
^ usernameExists 函数中最后的 else 语句。
标签: php error-handling