我目前正在通过教程学习PHP,我正在尝试运行以下代码,但是得到了一个无法解释的语法错误,而其他人似乎没有发现这些错误。
错误消息 解析错误:语法错误,意外&#39 ;;'在第12行的.... / users.php
第12行=
return (mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"), 0, 'user_id');
整页代码
<?php
function user_exists($username) {
$username = sanitize($username);
return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'"), 0) == 1) ? true : false;
}
function user_active($username) {
$username = sanitize($username);
return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `active` =1"), 0) ==1) ? true : false;
}
function user_id_from_username ($username) {
$username = sanitize($username);
return (mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"), 0, 'user_id');
}
function login ($username, $password) {
$user_id = user_id_from_username($username);
$username = sanitize($username);
$password = md5($password);
return(mysql_result(mysql_query("SELECT COUNT (`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"), 0) == 1) ? $user_id : false;
}
?>
答案 0 :(得分:5)
你错过了一个右括号) 你有3个开场但只有2个关闭...
答案 1 :(得分:4)
还有一个封闭的圆形支架。
/* v */
return (mysql_result(mysql_query("..."), 0, 'user_id')/* -> */)/* <- */;
/* ^ */
答案 2 :(得分:0)
试试这个,
function user_id_from_username ($username) {
$username = sanitize($username);
return (mysql_result(
mysql_query(
"SELECT `user_id` FROM `users` WHERE `username` = '$username'"
), 0
), 'user_id');
}