0

This is my function that is giving errors do not know why it is not executing at all and this if statement is line 86

if($stmt = $mysqli->prepare("SELECT time FROM login_attempts WHERE user_id=? AND time > '$valid_attempts'"))
{
    $stmt->bind_param('i', $user_id);
    $stmt->execute();
    $stmt->store_result();

    if($stmt->num_rows > 3)
    {
        return true;
    }
    else
    {
        return false;
    }
} 

I have this file to define details of db

<?php

define("HOST", "localhost:3311");     // The host you want to connect to.
define("USER", "root");    // The database username. 
define("PASSWORD", "root");    // The database password. 
define("DATABASE", "compared");    // The database name.

define("CAN_REGISTER", "any");
define("DEFAULT_ROLE", "member");

define("SECURE", FALSE);   
?>

And to create connection here this is the file

<?php 
include_once "C:/wamp64/www/includes/psl-config.php";

$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);       


?>

But it keeps giving error

Alex
  • 59
  • 4
  • Probably you have an error during connection. Try to catch it during connection attempt: http://stackoverflow.com/questions/15553496/new-mysqli-how-to-intercept-an-unable-to-connect-error – user4035 Oct 09 '16 at 20:58
  • In the previous 85 lines do you assign `$mysqli` anywhere else? You should bind `$valid_attempts` as well. – chris85 Oct 09 '16 at 20:59
  • Add `var_dump($mysqli); exit;` immediately before your if statement, what do you get? My guess is the instantiation of the mysqli class failed. – Steve Oct 09 '16 at 21:11

1 Answers1

0

Change '$valid_attempts' to ? and use bind params like you used with i

G. Mansour
  • 696
  • 6
  • 15