Hi all,

I'm trying to run an update query using the following code:


    $email = mysqli_real_escape_string($dbc, $_GET['e']);
    $ac = mysqli_real_escape_string($dbc, $_GET['ac']);

    $checkQuery = "SELECT subscribed FROM myUsers WHERE email='$email'";
    $checkQueryResult = @mysqli_query($dbc, $checkQuery);
    $row = mysqli_fetch_assoc($checkQueryResult);

    if ($row['subscribed'] == 1) {
        echo '<p><b>This account has already been activated!</b></p>';
    } else {     
        $updateQuery = "UPDATE myUsers SET subscribed=1, dateSubscribed=NOW() WHERE email='$email' AND ActivateCode='$ac'";
        $updateQueryResult = @mysqli_query($dbc, $updateQuery);

        if($updateQueryResult) {
            echo '<p>Thank you! Your subscription is complete!</p>';
        } else {
            echo '<p>Subscription failed!</p>';


I am getting the following output:

Thank you! Your subscription is complete!

Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in filepath/confirm.php on line 22

and the table is updated with the correct values.
From what I've read, this error is generated when the query fails. But how can that be so when the query runs and updates the table?

I'm confused.

Edited by Tinnin

5 Years
Discussion Span
Last Post by diafol

I would do this

$checkQueryResult = mysqli_query($dbc, $checkQuery)or die(mysqli_error($dbc));

The @ in front of @mysqli_query supresses errors, you don't want that there when you are debugging.

Setting this:

or die(mysqli_error($dbc));

Will show you any errors that are generated during the query as well.


Good call. I forgot that part but it's showing the same output regardless.


hmm, do you have the column 'dateSubscribed' set to datetime or timestamp (can't remember which one)? Also, is that table getting updated?

Edited by pixelsoul


It's set to DATE. I've another DATE column that I insert into using NOW() in another script and that one doesn't come up with any errors.
And yes, the table updates. Hence my confusion at the error message.

Column          Type           Null        Default      Comments
userID          mediumint(8)    No           
username        varchar(30)     No           
email           varchar(80)     No           
ActivateCode    varchar(90)     No           
dateCreated     date            Yes        NULL      
subscribed      tinyint(1)      No           
dateSubscribed  date            Yes        NULL      

Keyname Type    Unique  Packed  Column  Cardinality Collation   Null    Comment
PRIMARY BTREE   Yes No  userID  1   A   No  

Well, something is returning FALSE, somewhere.

Are you using this on the end of both the queries?:

or die(mysqli_error($dbc));

Edited by pixelsoul


<unhelpful and off-topic> Your title suggests that you are running on a quantum computer :)

Edited by diafol


My ex-girlfriend used to tell me she loved me and hated me at the same time. It was a quantum relationship, it got deleted :-))


I've had a thought though (it happens). If mysqli_free_result gets rid of the object then does that mean that it isn't needed with UPDATE? Or do I have that all wrong?


Regarding mysqli_query:

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

Click Here


Yup, your right. It doesn't need it with UPDATE. UPDATE returns a boolean which does not need to be freed. That actually crossed my mind for 2 seconds, but then I thought I was just being dumb.

Edited by pixelsoul


I think you've found the answer. You don't need to do this on an update as an update only returns true/false which is only sensible - there's no object to return. The select however should return data.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.