0

我目前正在通过教程学习 PHP,并且我正在尝试运行以下代码,但遇到无法解释的语法错误,似乎没有其他人发生过。

错误信息 解析错误:语法错误,意外的 ';' 在 ..../users.php 第 12 行

第 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;


}
?>
4

3 回答 3

5

你缺少一个右括号)你有 3 个开头但只有 2 个结尾...

于 2013-07-09T04:27:52.763 回答
4

又一个闭合的圆括号。

                                                           /* v */
return (mysql_result(mysql_query("..."), 0, 'user_id')/* -> */)/* <- */;
                                                           /* ^ */
于 2013-07-09T04:27:06.290 回答
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');
}
于 2013-07-09T04:29:14.810 回答