Jump to content
Sign in to follow this  
Trixx-

Login kļūda (OOP - Help)

Recommended Posts

Sveiki visiem. Vakar sāku mācīties php oop un tiku līdz tam, ka uztaisu login. Viss gāja labi, bet uz kāda momenta viss nobruka, neiet pati elemetārākā funckija, tikai nezinu kāpēc.

Kad mēģinu autorizēties, izmet šādu error - http://prntscr.com/gyhoj9

Kods - User.php

public static function checkUserData($login, $pass)
    {
        $db = Db::getConnection();

        $sql = "SELECT `username`, `password` FROM `users` WHERE username = '{$login}' AND password = '{$pass}'";
        $result = mysqli_query($db, $sql);

        $user = mysqli_fetch_array($result);
        if($user)
        {
            return $user['id'];
        }

        return false;
    }

Un šī ir funkcija, kurā tiek pielietota funckcija - UserController.php

public function actionLogin()
    {
        $db = Db::getConnection();

        $login = '';
        $pass = '';

        if (isset($_POST['enter']))
        {
            $login = mysqli_real_escape_string($db, $_POST['login']);
            $pass = mysqli_real_escape_string($db, $_POST['pass']);

            if (User::checkLogin($login))
            {
                $errors[] = 'Nepareizs lietotājvārds!';
            }

            if (User::checkPass($login, $pass))
            {
                $errors[] = 'Nepareiza parole!';
            }

            $userId = User::checkUserData($login, $pass);

            if($userId == false)
            {
                $errors[] = 'Nav tāda profila!';
            }
            else
            {
                User::auth($userId);
                header("location: /cabinet/");
            }
        }

        require_once(ROOT . '/views/user/login.php');

        return true;
    }

Nezinu kāpēc viņš raud par to 15 rindu, varbūt kāds varēs palīdzēt?

Edited by Trixx-

Share this post


Link to post
Share on other sites
4 minutes ago, Trixx- said:

$sql = "SELECT `username`, `password` FROM `users` WHERE username = '{$login}' AND password = '{$pass}'";

Kur tu izvelc id ?

  • Upvote 1

Share this post


Link to post
Share on other sites
Just now, PROaffDES said:

Kur tu izvelc id ?

Aaa, pēc tutoriala bija rakstīts SELECT *, bet es negribēju ar *, bet lai katrs izvelkas un nepamanīju, ka id nevelkas. Paldies! )

Share this post


Link to post
Share on other sites
16 hours ago, Trixx- said:

Aaa, pēc tutoriala bija rakstīts SELECT *, bet es negribēju ar *, bet lai katrs izvelkas un nepamanīju, ka id nevelkas. Paldies! )

Cik lasu tad lietot SELECT * neesot labi. Lai esot garaka rinda, bet labak itka esot lietot norades, pat tad ja lieto visus DB ierakstus.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.