检查用户是否是活动的mysql和PHP

时间:2013-09-28 11:54:50

标签: php mysql

大家好我有问题......这是我的代码;该功能是检查用户是否已激活他/她的帐户:

function is_active($username)
{
    $username=mysql_real_escape_string($username);
    require "dbc.php";
    $sql="SELECT COUNT users_temp,user_id 
            FROM users1 AS s1
            INNER JOIN users_temp AS s2
            ON users1,id = users_temp,user_id
            WHERE users1,username='{$username}'";

    $result=mysql_query($sql);

    if (!$result)
    {
        die(mysql_error());
    }

    return(mysql_result($result,0) == '0')? true : false;
}

当我运行此命令时,我收到以下错误消息:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'username='yu'' at line 5

我不知道我哪里出错了。这可能是一个小错误,但如果有人能帮助我那将是伟大的!

5 个答案:

答案 0 :(得分:1)

您应该使用点(。)来分隔表名和列名,而不是逗号

$sql="SELECT COUNT(users_temp.user_id) 
        FROM users1 AS s1
        INNER JOIN users_temp AS s2
        ON users1.id = users_temp.user_id
        WHERE users1.username='{$username}'";

答案 1 :(得分:1)

试试这个

$sql="SELECT COUNT (users_temp.user_id) 
        FROM users1 AS s1
        INNER JOIN users_temp AS s2
        ON s1.id = s2.user_id
        WHERE users1.username = '$username'";

答案 2 :(得分:0)

您不能使用单引号引用MySQL中的字段。

答案 3 :(得分:0)

您的错误在这里:

WHERE users1,username='{$username}'

请改为:

WHERE users1.username='$username'

或者这个:

WHERE users1.username='".$username."'

答案 4 :(得分:0)

你有user1,用户名。那是错的。

   $sql="SELECT COUNT users_temp,user_id 
    FROM users1 AS s1
    INNER JOIN users_temp AS s2
    ON users1,id = users_temp,user_id
    WHERE s1.username='$username'";

我希望这会对你有所帮助。