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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:12:57+00:00 2026-06-05T06:12:57+00:00

I am saving the gamestate from a mobile game on a MySql database. The

  • 0

I am saving the gamestate from a mobile game on a MySql database. The information is successfully saved, however it is echoing that there was an error in saving the game state. I’m still adjusting to php and not sure where this is coming from.

PS I know the SQL statement is insecure. Right now I’m just getting the fundamentals up and running as the statements and tables themselves will change soon.

Listining for incoming json:

    } else if ($tag == 'save_game_state') {
    $email = $_POST['email'];
    $virtumon = $_POST['monster'];
    $qty = $_POST['qty'];
    $exp = $_POST['exp'];
    $user = $db->saveGameState($email, $monster, $qty, $exp);
        if ($user) {
            $response["success"] = 1;
            $response["The game state has been successfully saved"];
         echo json_encode($response);
        } else {
            // user failed to store
            $response["error"] = 1;
            $response["error_msg"] = "Error occured in saving the game state";
            echo json_encode($response);
        }

Inputting the information into the DB and returning success/failure.

    public function saveGameState($email, $monster, $qty, $exp) {

    $result = mysql_query("INSERT INTO user_profiles(email, monster, qty, exp) VALUES('$email', '$monster', '$qty', '$exp')") or die(mysql_error());
    // TODO check for successful store
    $success = mysql_query("SELECT email, monster, qty, exp FROM user_profiles WHERE email = '$email' AND monster= '$monster' AND qty = '$qty' AND exp = '$exp'");
   if ($success) {
            return mysql_fetch_array($success);
    } else {
       return false;
   }
}
  • 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-05T06:12:59+00:00Added an answer on June 5, 2026 at 6:12 am

    Definitely shouldn’t run a SELECT after your INSERT to check and see if it worked. Just check what $result is after it’s ran. From

    From http://php.net/manual/en/function.mysql-query.php :

    For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error

    Try

    $result = mysql_query("INSERT INTO user_profiles(email, monster, qty, exp) VALUES('$email', '$monster', '$qty', '$exp')") or die(mysql_error());
    return $result;
    

    If you want to return the contents of what you just inserted then call another function after you run saveGameState. Though, if you already have the values you can just use those instead of querying the database again.

    You should also look into the use of PDO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am saving to the database from cakephp to mysql. When I view the
When saving my many-to-many related entities, the entities are saved ok. However the junction
Hello I am saving email address from a textarea in a database. Now i
I'm saving a string from PHP to MySQL like this.. $groupid = 13, 14,
Saving, editing and loading information. The information that I want to load is something
when saving hebrew to a mysql database (utf-8) i am getting it converted to
I'm saving contents of a particular div in mysql database as html elements. So
I am saving all the words from a file like so: sentence = fileName
I am saving a TimeSpan (from .NET) value in my db as BIGINT in
What you prefer about saving Webservice files in asp.net website(not websiteapplication). I saved WebService

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.