-1

我找不到丢失的花括号,但我收到了这条消息"Parse error: syntax error, unexpected $end in /site/public_html/core/functions/users.php on line 75"

对于以下代码..

<?php

function activate($email, $email_code) {
    $email = mysql_real_escape_string($email);
    $email_code = mysql_real_escape_string($email_code);

    if (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email' AND `email_code` = '$email_code' AND `active` = 0"), 0) == 1) {
        mysql_query("UPDATE `users` SET `active` = 1 WHERE `email` = '$email'");
        return true;
    }
    else {
        return false;
    }


function change_password ($user_id, $password) {
    $user_id = (int)$user_id;
    $password = md5($password);

    mysql_query("UPDATE `users` SET `password` = '$password' WHERE `user_id` = $user_id");
}

function register_user($register_data) {
    array_walk($register_data, 'array_sanitize');
    $register_data['password'] = md5($register_data['password']);

    $fields = '`' . implode('`, `', array_keys($register_data)) . '`';
    $data = '\'' . implode('\', \'', $register_data) . '\'';

    mysql_query("INSERT INTO `users` ($fields) VALUES ($data)");
    email($register_data['email'], 'Activate your account', "
    Hello " . $register_data['username'] . ", \n\n You need to activate your account, so use     the link below: \n\nhttp://www.mysite.com/activate.php?email=" . $register_data['email'] .   "&email_code=" . $register_data['email_code'] . "\n\n~Admin~ ");
}

function user_count() {
    return mysql_result(mysql_query("SELECT COUNT('user_id') FROM `users` WHERE `active` =  1"), 0);
}

function user_data($user_id) {
    $data = array();
    $user_id = (int)$user_id;

    $func_num_args = func_num_args();
    $func_get_args = func_get_args();

    if ($func_num_args &gt; 1) {
        unset($func_get_args[0]);

        $fields = '`' . implode('`, `', $func_get_args) . '`';
        $data = mysql_fetch_assoc(mysql_query("SELECT $fields FROM `users` WHERE `user_id` =   $user_id"));

        return $data;
    }

}

function logged_in() {
    return (isset($_SESSION['user_id'])) ? true : false;
}

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 email_exists($email) {
    $email = sanitize($email);
    return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email'"), 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

5 回答 5

2

看起来您的activate()函数缺少右括号}

function activate($email, $email_code) {
  $email = mysql_real_escape_string($email);
  $email_code = mysql_real_escape_string($email_code);

  if (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email' AND `email_code` = '$email_code' AND `active` = 0"), 0) == 1) {
    mysql_query("UPDATE `users` SET `active` = 1 WHERE `email` = '$email'");
    return true;
  } else {
    return false;
  }

} /* MISSING BRACKET */

function change_password ($user_id, $password) {
  ...
于 2013-07-10T22:51:45.353 回答
0

您的第一个function缺少右括号}

function activate($email, $email_code) {
    $email = mysql_real_escape_string($email);
    $email_code = mysql_real_escape_string($email_code);

    if (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email' AND `email_code` = '$email_code' AND `active` = 0"), 0) == 1) {
        mysql_query("UPDATE `users` SET `active` = 1 WHERE `email` = '$email'");
        return true;
    } else {
        return false;
    }

此外,缩进将有助于更轻松地发现此类问题(以及与您的大括号匹配的 IDE)

于 2013-07-10T22:52:17.030 回答
0

你没有关闭你的第一个功能,所以只需}在最后添加

function activate($email, $email_code) {
$email = mysql_real_escape_string($email);
$email_code = mysql_real_escape_string($email_code);

if (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email' AND `email_code` = '$email_code' AND `active` = 0"), 0) == 1) {
mysql_query("UPDATE `users` SET `active` = 1 WHERE `email` = '$email'");
return true;
} else {
return false;
}
}

哦,顺便说一句,停止使用常规的 PHP mysql_* 函数。自 PHP 5.5 起,它们将被弃用,因此请查看mysqliPDO

于 2013-07-10T22:52:32.493 回答
0

我认为第一个功能“激活”没有关闭,}在 else 关闭后添加。

function activate($email, $email_code) {
    $email = mysql_real_escape_string($email);
    $email_code = mysql_real_escape_string($email_code);

    if (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email' AND `email_code` = '$email_code' AND `active` = 0"), 0) == 1) {
        mysql_query("UPDATE `users` SET `active` = 1 WHERE `email` = '$email'");
        return true;
    } else {
        return false;
    }
}
^
here
于 2013-07-10T22:52:53.767 回答
-1

你错过了}

它应该是

function activate($email, $email_code) {
$email = mysql_real_escape_string($email);
$email_code = mysql_real_escape_string($email_code);

if (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email' AND `email_code` = '$email_code' AND `active` = 0"), 0) == 1) {
mysql_query("UPDATE `users` SET `active` = 1 WHERE `email` = '$email'");
return true;
} else {
return false;
}
} <---missing bracket here
于 2013-07-10T22:49:28.097 回答