0

For some reason I cannot get this to work for the life of me, I am new to prepared statements!


    $q = $dbc -> prepare ("SELECT * FROM accounts WHERE email = ? && logcount = ''");
    $q -> bind_param ('s', ($_SERVER['QUERY_STRING']));
    $row = $q -> fetch_array(MYSQLI_ASSOC);
    $q -> execute();
    $q -> store_result();
        if ($q -> num_rows == 1) {
            $q = $dbc -> prepare("UPDATE accounts SET logcount = '0' WHERE email = ?");
            $q -> bind_param('s', ($_SERVER['QUERY_STRING']));
            $q -> execute();
            echo '

Congratulations ' . $row['username'] . ' your account is now active!

'; }

Any ideas why $row['username'] will not print? It returns a : Call to undefined method mysqli_stmt::fetch_array()

Thanks.

1

3 Answers 3

4

You don't need fetch_array in this case.

If you want to use get the data from the query, you need to use bind_result and fetch after calling execute.

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

Comments

1

You need to call $q -> execute(); prior to fetching result.

1 Comment

I did that, and edited my question, it throws the same error, thanks.
0

You seem to be doing it wrong, when you call execute it returns a result object, which is what you call your fetch methods on:

$q = $dbc->prepare ("SELECT * FROM accounts WHERE email = ? && logcount = ''");
$q->bind_param ('s', ($_SERVER['QUERY_STRING']));

//Updated Here
$result = $q -> execute();

if ($result->num_rows == 1)
{
    $assocData = $result->fetch_array(MYSQLI_ASSOC);
    //Do other stuff
}                                        

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.