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 7830165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:06:14+00:00 2026-06-02T11:06:14+00:00

I have a problem when performing mysql commands when I invoke a function in

  • 0

I have a problem when performing mysql commands when I invoke a function in another file. If I have the code in the same file, it works fine. The code looks like:

authenticate:

{
    $conn = new mysqli($dbserver, "dbuser", "pass", $dbname);
    $sql = 'SELECT userId, salt, pwd, isAdmin FROM users where username = ?';
    $stmt = $conn->stmt_init();
    $stmt->prepare($sql);
    $stmt->bind_param('s', $username);
    $stmt->bind_result($userId, $salt, $storedPwd, $isAdmin);
    $stmt->execute();
    $stmt->fetch();
}

Now, if I call a function, immediately after fetch, it fails on the bind_param line. I call it like this:

updateUserActivity ($conn, $tpcLang, 'LI', $userId);

the beginning of this function is:

function updateUserActivity ($conn, $lang, $activityType, $userId)
{
    // check that activity is valid
    $sql = 'SELECT activityType
            FROM activityType  
            WHERE activityType = ?';
    $stmt = $conn->stmt_init();
    $stmt->prepare($sql);
    $stmt->bind_param('s', $activityType);
    $stmt->bind_result($activityTypeInDB);
    $stmt->execute();
    $stmt->fetch();

    if ($activityType == $activityTypeInDB){
        $success=1;
    } else {
       $success=0;
       $msg = $lang->get('UPDATE_USER_INVALID_ACTIVITY_ERROR_MSG') . " " . $activityType . " (" . $stmt->errno . "):  " . $stmt->error;
       error_log ($msg);
    }
    // continue on to add a row in the userActivity table
} 

The error I get on the bind_param is: invalid object or resource mysqli_stmt, and the DB error is: Commands out of sync; you can’t run this command now.

Any suggestions would be greatly appreciated.

  • 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-02T11:06:16+00:00Added an answer on June 2, 2026 at 11:06 am

    try adding this after your fetch.

    mysqli_free_result($result);
    

    or

    mysqli_close($conn);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with fancybox. I want to write a function that will run
I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
I have a problem with a subquery involving IPV4 addresses stored in MySQL (MySQL
I have a weird problem with ExecuteQuery in that it isn't working when performing
I have a similar problem with delete command too.. function deleteUsers($userID) { foreach($userID as
I have a problem in integrating PHP and JQuery: My main file is MyFile.html
There seems to be a problem with the code I have for calling php
To use code I have written for performing calculations, I need to read in
the problem I have is that when making same calculations in PHP and in
I have problem with reporting services rendering on the client which is performing very

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.