gpt4 book ai didi

php - 意外的T_CATCH,预期为T_FUNCTION

转载 作者:行者123 更新时间:2023-12-03 08:16:21 25 4
gpt4 key购买 nike

今天,在尝试编写此User类时,我在下面突出显示的行上遇到了上述错误,想知道您对此有何想法。

class User {
public $username;
public $password;
public $user_info;
public $connection;

function __construct($username) {
$connection = new Database();
try {
$user_info = $connection->query("SELECT * FROM `users` WHERE `username` = '$username'");
if ($user_info == null) {
throw new Exception("Could not find user details, please try again later!");
}
***} catch (Exception $login) {***
die($login->getMessage());
}
session_start();
$_SESSION["dgs_tech"] = $user_info;
}

function update_info() {
$user_info = $connection->query("SELECT * FROM `users` WHERE `username` = '$username'");
if ($user_info == null) {
throw new Exception("Could not find user details, please try again later!");
}
} catch (Exception $login) {
die($login->getMessage());
}
$_SESSION{"dgs_tech"] = $user_info;
}

function return_info() {
$text = "<p>"
foreach($user_info as $name => $item) {
$text += "<h1>$name:</h1>$item<br/>";
}
$text += "</p>";
return $text;
}
}

最佳答案

我认为此错误即将起作用update_info()
您那里没有“try {”

关于php - 意外的T_CATCH,预期为T_FUNCTION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3591640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com