mysql_result错误找不到用户

时间:2015-02-24 10:52:54

标签: php html mysql localhost

我有这个功能:

function user_exists($username) {
    $username = sanitize($username);
    $query = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'"); //or die(mysql_error());
    return (mysql_result($query, 0) == 1) ? true : false;
}

用于检查用户是否存在..

这个论坛:

    <?php

    if (empty($_POST) === false) {
        $username = $_POST['username'];
        $password = $_POST['password'];

        if (empty($username) === true or empty($password) === true) {
            $errors[] = 'You need to enter username and password';
        } else if (user_exists($username) === false) {
            $errors[] = 'We can\'t find that username. Have you '.'<a href="registeration.php">registered</a>'.'?';
        } else if (user_active($username) === false) {
          $errors[] = 'You haven\'t activated your account yet !';
        } else {

            if (strlen($password) > 32) {
                $errors[] = 'Password is too long';

            }

            $login = login($username, $password);
            if ($login === false) {
               $errors[] = 'The username / password compination is incorrect';
            }else {
                $_SESSION['user_id'] = $login;
                header('location: index.php');


            }
        }


    } else {

        $errors[] = 'No data recieved';

    }
    include_once "panels/header.php";
    if (empty($errors) === false) {
    ?>

        <div class="row">
            <div class="container">
                <div class="col-xs-6 col-sm-3 col-md-9">
                    <b>We tried to log you in, but ...</b><br />
                    <?php
                     echo output_errors($errors);
                    }?>

但它给了我这个错误:

  

警告:mysql_result()要求参数1为resource,boolean   在第45行的C:\ xampp \ htdocs \ Knowtodo \ functions \ users.php中给出

并显示找不到用户:

  

我们试图让您登录,但是......我们无法找到该用户名。有你   注册

你能帮我吗...

由于

0 个答案:

没有答案