-4

My php code:

<?php
    require("password.php");

    $connect = mysqli_connect(...);

    //connect to the database 
   //  include 'finance_connection.php';

    $username = $_POST["username"];
    $password = $_POST["password"];

    $statement = mysqli_prepare($connect, "SELECT * FROM user WHERE username = ?");
    mysqli_stmt_bind_param($statement, "s", $username);
    mysqli_stmt_execute($statement);
    mysqli_stmt_store_result($statement);
    mysqli_stmt_bind_result($statement, $colUserID, $colName, $colUsername, $colAge, $colPassword, $colEmail);

    $response = array();
    $response["success"] = false;  

    while(mysqli_stmt_fetch($statement)){
        if (password_verify($password, $colPassword)) {
            $response["success"] = true;  
            $response["name"] = $colName;
            $response["age"] = $colAge;
            $response["email"] = $colEmail;
        }
    }

    echo json_encode($response);
?>

the error

Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /storage/ssd4/966/2373966/public_html/Login2.php on line 13

Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /storage/ssd4/966/2373966/public_html/Login2.php on line 14

Warning: mysqli_stmt_store_result() expects parameter 1 to be mysqli_stmt, boolean given in /storage/ssd4/966/2373966/public_html/Login2.php on line 15

Warning: mysqli_stmt_bind_result() expects parameter 1 to be mysqli_stmt, boolean given in /storage/ssd4/966/2373966/public_html/Login2.php on line 16

Warning: mysqli_stmt_fetch() expects parameter 1 to be mysqli_stmt, boolean given in /storage/ssd4/966/2373966/public_html/Login2.php on line 21

mysqli_stmt_bind_param($statement, "s", $username); mysqli_stmt_execute($statement); mysqli_stmt_store_result($statement); mysqli_stmt_bind_result($statement, $colUserID, $colName, $colUsername, $colAge, $colPassword, $colEmail);

i think there's a problem with these line of code

Dharman
  • 26,923
  • 21
  • 73
  • 125
  • 1
    Take the [tour](https://stackoverflow.com/tour) and read through the [help center](https://stackoverflow.com/help) to improve your question and learn why you are receiving downvotes – Milan Chheda Aug 19 '17 at 08:24
  • Your connection object variable name is `$connection` but in query you used `$connect` – JYoThI Aug 19 '17 at 08:27
  • [`mysqli_prepare()`](http://php.net/manual/en/mysqli.prepare.php) returns `FALSE` when the connection is not established or the query is incorrect. Use [`mysqli_connect_error()`](http://php.net/manual/en/mysqli.connect-error.php) after [`mysqli_connect()`](http://php.net/manual/en/mysqli.construct.php) and [`mysqli_error()`](http://php.net/manual/en/mysqli.error.php) after `mysqli_prepare()` to find out if and why they failed. – axiac Aug 19 '17 at 08:47

2 Answers2

0

at first glance these should be the same:

$connection = mysqli_connect(...);
.
.
.
$statement = mysqli_prepare($connect, "SELECT * FROM user WHERE username = ?");

Wee Zel
  • 1,216
  • 9
  • 10
0

1st : your connection object variable name is $connection but in query you used $connect. so mysqli_prepare will return Boolean value false that's why you get those errors.

$statement = mysqli_prepare($connection , "SELECT * FROM user WHERE username = ?");
JYoThI
  • 11,793
  • 1
  • 10
  • 25
  • same error encountered is there any problem with these line of code? cuz i think the error happen here mysqli_stmt_bind_param($statement, "s", $username); mysqli_stmt_execute($statement); mysqli_stmt_store_result($statement); mysqli_stmt_bind_result($statement, $colUserID, $colName, $colUsername, $colAge, $colPassword, $colEmail); – Williams John Aug 19 '17 at 08:34
  • `$connect = mysqli_connect(...) or die(mysqli_connect_error());` add this line and know that connection created or not . @WilliamsJohn – JYoThI Aug 19 '17 at 08:37