0

Sorry for the nooby question but I am new to php and couldn't find an exact answer to this question.

So anyway, what I want to do is create a php script that displays a captcha notice if a password is incorrectly entered three times. The trouble I am having is with the query I believe, I can't figure out get an integer value directly from the table. Here is my code, any answers would be appreciated :)

$get_login_attempts = "SELECT time FROM login_attempts WHERE email='".mysql_real_escape_string($username)."'";
$run_get_login_attempts = mysql_query($get_login_attempts);
if($run_get_login_attempts == 3){
    $captcha = true;
    require_once('recaptchalib.php');
    $privatekey = "6LcmuvcSAAAAAPsEOXYm_lWWOPaQYLAyUo3HQ91Q";
    $resp = recaptcha_check_answer($privatekey,
            $_SERVER['REMOTE_ADDR'], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
    if(!$resp->is_valid)
        die("The reCaptcha was not entered correctly, please try again");
user3918443
  • 105
  • 1
  • 13
  • 2
    You need to actually fetch the result of your query. But before you go any further using the deprecated `mysql_*` functions, I would _highly_ recommend that you switch to [PDO](http://us2.php.net/manual/en/book.pdo.php) or [mysqli](http://us2.php.net/manual/en/book.mysqli.php). – Patrick Q Aug 07 '14 at 13:06

2 Answers2

0

You need to fetch the results first using mysql_fetch_assoc, for example. See the phpdoc for more information (actually a deprecated method) http://php.net/manual/en/function.mysql-fetch-assoc.php.

$row = mysql_fetch_assoc($run_get_login_attempts);
if($row['time'] == 3) {
   // ...
}
mathf
  • 316
  • 2
  • 10
0

mysql_query() will return a ressource. You need to use functions like mysql_fetch_array() or mysql_fetch_assoc() to get results.

$run_get_login_attempts = mysql_query($get_login_attempts);
$row = mysql_fetch_assoc($run_get_login_attempts);

echo $row['time'];

See also this : Why shouldn't I use mysql_* functions in PHP?

Community
  • 1
  • 1
fdehanne
  • 1,658
  • 1
  • 16
  • 32