0

So, I'm having an issue with checking if a variable exists within the db in my registration page.

$Key = mysqli_real_escape_string($mysqli, $_POST['key']);

$result = $mysqli->query("SELECT * FROM def WHERE key='$Key'");
$row = mysqli_fetch_array($result);
$rowcheck = $result->num_rows;
if(is_array($row))
{
    //rest of registration continues if key is in the db
}
else
{
    //error echo stating key is invalid
}

The problem I am having is that even if the stated key is correct, I am still getting the else statement error. It does not let me register, it will just tell me the key is invalid. What am I doing wrong here? Because if i change is_array to if the $rowcheck = 1 it works, but then typing an invalid key works. given it does not actually register the account, it still stays registration success. Any help will be appreciated, as the rest of the site is set up and I encountered this error after finding the registration successful bug. Thank you again Stackoverflow,

Zero

Marc B
  • 356,200
  • 43
  • 426
  • 500
Absolute Zero
  • 25
  • 1
  • 7
  • 2
    You're simply assuming the query succeeded. `var_dump($row)`. If that says `bool(false)`, then something blew up. – Marc B Aug 31 '15 at 20:13
  • try doing a `var_dump` of `$row` to see what's actually being returned. – Pavlin Aug 31 '15 at 20:13
  • I echoed out a var_dump of $row, and nothing was displayed on the page. Would this mean that nothing is being returned? If so, where would the error lie within the code? I double checked my query with the db, its correct. The only thing that I could think is that the key is in the third row over, there are 2 empty fields before it. – Absolute Zero Aug 31 '15 at 20:21
  • @MarcB It 'sho 'nuff did http://www.youtube.com/watch?v=uHkvD7-u7y8 – Funk Forty Niner Aug 31 '15 at 20:24

0 Answers0