Going out of my mind on this one. Here's the situation and what I've tried so far:
I've got a simple form that collects an email and a password which are then supposed to be inserted into a database table with three columns. The table is called users
and the three columns are called userID
, userEmail
, userPassword
. Here is my starting code:
// hash the password value
$pass = hash_hmac('sha256', $p, 'c#hArl891', true);
// Query the database:
$q = "INSERT INTO users (userEmail, userPassword) VALUES ('".$e."','".$pass."')";
$r = mysqli_query ($dbc, $q);
if (mysqli_num_rows($r) == 1) { // Successful insertion.
What happened with this code is that the email (variable $e
) showed up correctly in the database and the password was a garbled mess (a side issue) but the mysqli_num_rows($r)
returned this error:
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
I've tried replacing the hashed value with just $p, I've tried replacing both variables with constants, I've tried using back-ticks around the table name and field names, and I've tried a suggestion I found online to use braces:
$q = "INSERT INTO users (`userEmail`,`userPassword`) VALUES ('{$e}','{$pass}')";
Nothing seems to work to get mysqli_num_rows($r) == 1
.
According to the returned error message, I'm seeing variable values of:
[e] => webmaster@brukenet.com
[p] => 12345
[pass] => Ç o’,YÊ2ý€|y:fز"?ïÑ`{a]YÑ=Âk¼
[q] => INSERT INTO `users` (`userEmail`, `userPassword`) VALUES ('webmaster@brukenet.com', 'Ç o’,YÊ2ý€|y:fز"?ïÑ`{a]YÑ=Âk¼')
[r] => 1
and
[dbc] => mysqli Object
These would seem to indicate that $r
DOES equal 1
but this is taken directly from the same error message.
I've been up all night and I'm thinking this must be something obvious that I'm just over-looking but I just can't see it.