致命错误:函数名称必须是.. PHP错误中的字符串
您好,我有一个名为 User 的类和一个名为 insertUser() 的方法。
function insertUser($first_name, $last_name, $user_name, $password, $email_address, $group_house_id)
{
$first_name = mysql_real_escape_string($first_name);
$last_name = mysql_real_escape_string($last_name);
$user_name = mysql_real_escape_string($user_name);
$password = mysql_real_escape_string($password);
$email_address = mysql_real_escape_string($email_address);
$query = "INSERT INTO Users
(FirstName,LastName,UserName,Password,EmailAddress, GroupHouseID) VALUES
('$first_name','$last_name','$user_name','$password','$email_address','$group_house_id')";
$mysql_query($query);
}
我这样称呼它:
$newUser = new User();
$newUser->insertUser($first_name, $last_name, $user_name, $email, $password, $group_house_id);
当我运行代码时,我收到此错误:
Fatal error: Function name must be a string in /Library/WebServer/Documents/ORIOnline/includes/class_lib.php on line 33
有人知道我在做什么吗?另外,这是我第一次尝试 OO PHP。
干杯,
琼斯
Hi I have a class called User and a method called insertUser().
function insertUser($first_name, $last_name, $user_name, $password, $email_address, $group_house_id)
{
$first_name = mysql_real_escape_string($first_name);
$last_name = mysql_real_escape_string($last_name);
$user_name = mysql_real_escape_string($user_name);
$password = mysql_real_escape_string($password);
$email_address = mysql_real_escape_string($email_address);
$query = "INSERT INTO Users
(FirstName,LastName,UserName,Password,EmailAddress, GroupHouseID) VALUES
('$first_name','$last_name','$user_name','$password','$email_address','$group_house_id')";
$mysql_query($query);
}
And I call it like this:
$newUser = new User();
$newUser->insertUser($first_name, $last_name, $user_name, $email, $password, $group_house_id);
When I run the code I get this error:
Fatal error: Function name must be a string in /Library/WebServer/Documents/ORIOnline/includes/class_lib.php on line 33
Anyone know what I am doing wronly? Also, this is my first attempt at OO PHP.
Cheers,
Jonesy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
$mysql_query($query);
=>mysql_query($query);
。请注意缺少的美元。如果您尝试对变量使用函数调用语法,它会查找名称由变量值指定的函数。在这种情况下,您没有mysql_query
变量,因此它什么也没有返回,这不是一个字符串,从而给您带来错误。$mysql_query($query);
=>mysql_query($query);
. Note the missing dollar. If you try to use function call syntax on a variable, it looks for a function with the name given by the value of the variable. In this case, you don't have amysql_query
variable, so it comes back with nothing, which isn't a string, and thus gives you the error.您在 mysql_query 上有一个杂散的
$
。删除它:You have a stray
$
on mysql_query. Remove it:对于下一个新手,如何触发/解决此错误
“PHP Fatal error: Function name must be a string in ...”
的另一个示例如下;
假设你有一个关联数组;
解决方案:
Just for the next newbie, another example of how this error
" PHP Fatal error: Function name must be a string in ..."
is triggered / and solved is as below;
Say you have an associative array;
Solution: