1

     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.

2
  • 3
    You are not SELECTing anything. Where would you expect the user name to come from? Also, I don't see a "fetch array" instrcution in your code? Commented Apr 15, 2011 at 12:18
  • Hmmm I am still very new to this, I apologise. Commented Apr 15, 2011 at 12:28

2 Answers 2

1
 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.

Sign up to request clarification or add additional context in comments.

Comments

0

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:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.