Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7798361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:58:55+00:00 2026-06-01T23:58:55+00:00

Can someone tell me when you prepare() a statement (in my case an update

  • 0

Can someone tell me when you prepare() a statement (in my case an update statement) and then execute() it, I then check using rowCount() after the update query (see code below) if rowCount() > 0 if it is then a match was found and update took place, but I then got an else statement.

To make sure I am not confusing myself with syntax errors and conditions in statements, I want to ask in my code below (have commented specific area in detail) does the else statement basically mean cannot update because a match was not found and/or a possible syntax error or some other error? I think it means what I put in bold just want to ensure I am not confusing myself.

Please ignore the SQL UPDATE syntax itself in the prepare statement as it’s wrong and will deal with later. I think the code explains better along with a detailed comment in area I am talking about.

// check if key is set and alphanumeric and equals 40 chars long
// we use sha1 so it will always be 40 chars long.
if(isset($_GET['key']) && ctype_alnum($_GET['key']) && strlen($_GET['key']) == 40){
$key = trim($_GET['key']);
}

// if key isset and valid
if(isset($key)){


try {
    // connect to database
    $dbh = sql_con();

    // checke if activation key matches and user_uid matches
    $stmt = $dbh->prepare("
            SELECT
              users_status.user_uid,
              users_status.user_activation_key
            FROM
              users_status
            JOIN
              users
            ON
              users_status.user_activation_key = ?
            AND
              users_status.user_uid = users.user_uid LIMIT 1");

    // execute query
    $stmt->execute(array($key));

    // if row count greater than 0 then match found
    if ( $stmt->rowCount() > 0 ) {

        // user verified; we now must update users status in users table to active = 1
        // and set the user_activation_key in the users_status to NULL
        $stmt = $dbh->prepare("
            UPDATE
              users.user_status,
              users_status.user_activation_key
            SET
              user_status = ".USER_STATUS_ACTIVE.",
              user_activation_key = NULL
            JOIN
              users
            ON
              users_status.user_activation_key = ?
            AND
              users_status.user_uid = users.user_uid LIMIT 1");

        // execute query
        $stmt->execute(array($key));

        if ( $stmt->rowCount() > 0 ) {

            echo 'account now activated';
            exit;

        } else {
            // update not sucessful
            // THIS IS THE BIT IM CONFUSED WITH;
            // IF RETURNED RESULT IS 0 (WHICH IT WILL BE IF I GET HERE WHEN RUNNING SCRIPT)
            // THEN I GUESS THAT MEANS THERE WAS NOT AN ERROR IN SQL SYNTAX BUT
            // CONDITION IN SQL STATEMENT COULD NOT BE MATCHED ? IS THAT CORRECT WHAT I AM THINKING ?
            // IF I AM CORRECT THEN OBVIOUSLY I WILL DISPLAY A MESSAGE TO USER AND EXIT HERE;
            // AS IF I AM THINKING RITE ANY SYNTAX ERROR WOULD BE CAUGHT BY CATCH BLOCK AND THIS ELSE STATEMENT
            // MEANS COULD NOT UPDATE BECAUSE NO MATCH IN UPDATE QUERY COULD BE FOUND ?
        }


    } // else no match found
    else {

        // no match found invalid key
        echo '<h1>Invalid Activation Link</h1>';

        $SiteErrorMessages =
        "Oops! Your account could not be activated. Please recheck the link in your email.
        The activation link could not be found or the account has already been activated.";

        SiteErrorMessages();

        include($footer_inc);
        exit;

    }

    // close database connection
    $dbh = null;

} // if any errors found log them and display friendly message
catch (PDOException $e) {
    ExceptionErrorHandler($e);
    require_once($footer_inc);
    exit;
}

} else {

// else key not valid or set
echo '<h1>Invalid Activation Link</h1>';

$SiteErrorMessages =
"Oops! Your account could not be activated. Please recheck the link in your email.
The activation link appears to be invalid.<br /><br />
If the problem persists please request a new one <a href='/member/resend-activation-email'>here</a>.";

SiteErrorMessages();

include($footer_inc);
exit;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:58:56+00:00Added an answer on June 1, 2026 at 11:58 pm

    You are right:

    if $stmt->rowCount() == 0
    

    Then it means no rows has been updated.

    If you heve sql errors or errors while executing query you receive a FALSE return value or also a PDO EXCEPTION when you execute

      execute(array($key));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone tell me, when you for example update, insert, delete.. should you then
Can someone tell me how to change directories using FtpWebRequest? This seems like it
Can someone tell what is wrong with this query? sqltext = SELECT utyp, count(*)
Can someone tell me why this processes all the files and then does it
Can someone tell me the regex to see if something is surrounded in double
Can someone tell me is it possible to have an if statement similar to
Im a little puzzled here, can someone just look over this query and tell
Can someone tell me if its possible to create relative as opposed to absolute
Can someone tell me why this is not displaying the form? If I go
Can someone tell me how i can change the .xml file that a flash

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.