Reputation: 1866
if ($q -> num_rows == 1) {
$q = $dbc -> prepare("UPDATE accounts SET logcount = '0' WHERE email = ?");
$q -> bind_param('s', ($_SERVER['QUERY_STRING']));
$q -> fetch_array(MYSQLI_ASSOC);
$q -> execute();
echo 'Congratulations ' . $q['username'] . ' your account is now active!
';
}
How come when using $q['username'] it doesn't fetch the row username?
I am new to using prepared statements please forgive me :D!
Thanks.
Upvotes: 1
Views: 1471
Reputation: 76240
You are executing an UPDATE
statement. To retrieve data you should use a SELECT
statements. UPDATE
statements returns only true or false; also mysql function fetch_array()
should trow an error if you are trying to fetch a non result
.
Since you code is starting with if ($q -> num_rows == 1) {
, I think that $q -> fetch_array(MYSQLI_ASSOC);
is referring to a previous query. To separate and do not overwrite the two queries you should execute this code instead:
if ($q -> num_rows == 1) {
$q2 = $dbc -> prepare("UPDATE accounts SET logcount = '0' WHERE email = ?");
$q2 -> bind_param('s', ($_SERVER['QUERY_STRING']));
$q -> fetch_array(MYSQLI_ASSOC);
$q2 -> execute();
echo 'Congratulations ' . $q['username'] . ' your account is now active!';
}
References:
Upvotes: 0
Reputation: 206709
if ($q -> num_rows == 1) {
$q = $dbc -> prepare("UPDATE ...");
You are overwriting your $q
variable which presumably held the result of a SELECT
(guessing).
Use a different variable for the UPDATE
part.
Upvotes: 1