-1

I've got a problem. Here's my PHP script and when I run this code it gives me this error,

Fatal error: Call to a member function bind_param() on boolean in C:\xampp\htdocs\osadnicy\zaloguj.php on line 30.

How can I fix it ? Please help.

<?php

    session_start();

    if ((!isset($_POST['login'])) || (!isset($_POST['haslo'])))
    {
        header('Location: index.php');
        exit();
    }

    require_once "connect.php";

    $polaczenie = @new mysqli($host, $db_user, $db_password, $db_name);

    if ($polaczenie->connect_errno!=0)
    {
        echo "Error: ".$polaczenie->connect_errno;
    }
    else
    {
        $login = $_POST['login'];
        $haslo = $_POST['haslo'];

        $login = htmlentities($login, ENT_QUOTES, "UTF-8");


        $zapytanie = $polaczenie->prepare("SELECT * FROM uzytkownicy WHERE user = ? AND haslo = ?");
        $zapytanie->bind_param('ss', $login, $haslo);

        if ($rezultat = $zapytanie->execute())
        {
            $ilu_userow = $rezultat->num_rows;
            if($ilu_userow>0)
            {
                $wiersz = $rezultat->fetch_assoc();

                if (password_verify)
                {
                    $_SESSION['zalogowany'] = true;
                    $_SESSION['id'] = $wiersz['id'];
                    $_SESSION['user'] = $wiersz['user'];
                    $_SESSION['drewno'] = $wiersz['drewno'];
                    $_SESSION['kamien'] = $wiersz['kamien'];
                    $_SESSION['zboze'] = $wiersz['zboze'];
                    $_SESSION['email'] = $wiersz['email'];
                    $_SESSION['dnipremium'] = $wiersz['dnipremium'];

                    unset($_SESSION['blad']);
                    $rezultat->free_result();
                    header('Location: gra.php');
                }
                else
                {
                    $_SESSION['blad'] = '<span style="color:red">Nieprawidłowy login lub hasło!</span>';
                    header('Location: index.php');
                }

            } else {

                $_SESSION['blad'] = '<span style="color:red">Nieprawidłowy login lub hasło!</span>';
                header('Location: index.php');

            }

        }

        $polaczenie->close();
    }

?>
HaveNoDisplayName
  • 7,711
  • 106
  • 32
  • 44
  • Include code in the question. – Script47 Dec 31 '15 at 18:13
  • is this one file code or multiple files ? – Venkat.R Dec 31 '15 at 18:14
  • Multiple (7files + 1 *.sql) – Kamil Rudny Dec 31 '15 at 18:15
  • You've got code : http://pastebin.com/8WSMRbfS – Kamil Rudny Dec 31 '15 at 18:15
  • Sorry, but pastebin is _not_ a replacement for posting the relevant parts of your code inline inside the question. That is clearly explained in the "how to ask section": http://stackoverflow.com/help/how-to-ask – arkascha Dec 31 '15 at 18:20
  • check the return value from `$zapytanie = $polaczenie->prepare("...`. Then figure out what wrong with your query: http://stackoverflow.com/questions/2552545/mysqli-prepared-statements-error-reporting – Dan Dec 31 '15 at 18:29
  • @KamilRudny, Check my answer with Reference URL. let us know if your issue still exist. – Venkat.R Dec 31 '15 at 18:35
  • `if (password_verify)` that is being treated as a constant and error reporting would have told you about it (and helped you in regards to other possible issues). The syntax is `if (password_verify('rasmuslerdorf', $hash))` and used as a "function" `password_verify()`, as per http://php.net/manual/en/function.password-verify.php and we've no way to tell if you did use `password_hash()` in the first place, if your POST arrays have values, or the password column is long enough. – Funk Forty Niner Dec 31 '15 at 19:34

1 Answers1

0

Correct the below part in your Code Snippet.

<?php
/* Create a prepared statement */
$zapytanie = $polaczenie->stmt_init();

if ($zapytanie->prepare("SELECT * FROM uzytkownicy WHERE user = ? AND haslo = ?"))
    {
    $zapytanie->bind_param('ss', $login, $haslo);
    if ($rezultat = $zapytanie->execute())
        {

        // Your Code

        }
    }

Reference URL:
http://php.net/manual/en/mysqli-stmt.prepare.php

Venkat.R
  • 6,616
  • 5
  • 34
  • 57