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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:26:30+00:00 2026-06-06T07:26:30+00:00

called a function like :- $setmessage = setlatestmessage($sessionid, $sendersuserid, $message1); the function is in

  • 0

called a function like :-

$setmessage = setlatestmessage($sessionid, $sendersuserid, $message1);

the function is in file functions.php, which i had included in this file
The function is :-

function setlatestmessage($sessionid, $userid, $message, $status = 0) {
    $dbc = mysqli_connect(hostname, username, password, database)
            or die("Error connecting database");

    // there was no row, so just add a row
    $query2 = "insert into table(session_id, user_id, message, status) values ( $sessionid, $userid, '$message', $status)";
    mysqli_query($dbc, $query2);

    // if a row was affected, close connection and send true
    if (mysqli_affected_rows($dbc) == 1) {
        mysqli_close($dbc);
        return TRUE;
    }
    mysqli_close($dbc);
    return FALSE;
}

now, just after i had called this function, the script goes like

if (!$setmessage) {
                echo '<status>0</status>';
            } else {
                // fetch id of the row just inserted
                $query2 = "select id from game_messages where session_id = $sessionid and message = '$message1' and user_id = $sendersuserid order by datetime desc limit 1";
                $result2 = mysqli_query($dbc, $query2);

                if (mysqli_num_rows($result2) == 0) {
                    // if no row was returned
                    // case never should happen
                    echo '<status>10</status>';
                }
                else{echo'done';}

The output i get is 10.

However, if i just place a sleep(50) under the function call, or i just code what the function is doing, instead of the function call, i get correct output.
Cant figure out why this is happening.

  • 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-06T07:26:33+00:00Added an answer on June 6, 2026 at 7:26 am

    It would be much easier and simpler if you would return the ID generated with your last insert query in setlatestmessage() function using mysqli_insert_id() or false on error. Then you would simply check:

    $messageID = setlatestmessage($sessionid, $sendersuserid, $message1);
    
    if ($messageID !== false)
    {
        echo '<status>0</status>';
    }
    else
    {
        echo '<status>10</status>';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file called function.php that has a function like this: public function
Hey I have a function which is called from a html link like this:
I'm using linux. I have a function called like: PlayBackgroundIntroMusic((char *)IntroMusic); The functions is:
Suppose I have a free function called InitFoo . I'd like to protect this
How can I check which event called my function on JavaScript with jQuery? Like
I'm writing an insertion sort in MATLAB. I called my function like this: >>
Symfony1 had a helper function called auto_link_text() , which parsed a block of text
I'd like to build a function that returns false if it's been called less
While I'm going through Python code and seeing functions called, I notice things like
I have a function called PreProcessSource, which allocates a boost::wave::context and does some preprocessing;

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.