一段简单的PHP代码:
#login.php
$_SESSION['valid_user_id'] = getUserId($username, $password);
#user_auth_fns.php
function getUserId($username, $password)
{
    $username = addslashes($username);
    $username = mysql_real_escape_string($username);
    $password = addslashes($password);
    $password = mysql_real_escape_string($password);
    $conn = db_connect();
    $result = $conn->query("select id from user where username='$username' and password= sha1('$password')");
    if (!$result) {
        throw new Exception('Could not retrieve your user id.');
    }
    if ($result->num_rows > 0) {
        return $result;
    } else {
        throw new Exception('Could not retrieve your user id.');
    }
}"return $result“是错误的,但是我不知道应该放什么才能返回某个用户的id。PHP手册也没有提供答案。我知道这个函数是有效的,因为替换
通过return“$result”返回测试
按预期返回正确的值。
发布于 2011-10-13 20:57:41
试试这个:
if ($result->num_rows > 0) {
    $tmp = $result->fetch_assoc();
    $return = $tmp['id'];
    return $return;
} else { ...https://stackoverflow.com/questions/7754423
复制相似问题