Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting state from MySql via PHP + JSON
    primarykey
    data
    text
    <p>I am building an android game in which I am attempting to download the user's profile from a MySql db into the local SQLite DB. I am able so the profile to the server but unable to retrieve it. </p> <p>Here are the relevant android methods, there should be no issues with them they function properly although the logic itself may be off. </p> <pre><code> //LOAD PROFILE CLASS userFunctions.getServerGameState(email, monster, qty, exp); db.saveLocalGameSate(monster, qty, exp); //FUNCTIONS CLASS public JSONObject getServerGameState(String email, String monster, int qty, int exp) { // Building Parameters List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;(); params.add(new BasicNameValuePair("tag", get_game_state)); params.add(new BasicNameValuePair("email", email)); params.add(new BasicNameValuePair("monster", monster)); params.add(new BasicNameValuePair("qty", Integer.toString(qty))); params.add(new BasicNameValuePair("exp", Integer.toString(exp))); // getting JSON Object JSONObject json = jsonParser.getJSONFromUrl(monsterURL, params); // return json return json; } //DB HANDLER CLASS public void saveLocalGameSate(String monster, int qty, int exp){ SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_MONSTER, monster); // Do they own it values.put(KEY_QTY, qty); // Number of things they own values.put(KEY_EXP, exp); // monster's level // Inserting Row db.insert(USERPROFILES_TABLE, null, values); db.close(); // Closing database connection } </code></pre> <p>Here is the PHP, I believe my error lies in one of these two files. </p> <p>index.php</p> <pre><code> else if ($tag == 'get_game_state') { $email = $_POST['email']; $monster = $_GET['monster']; $qty = $_GET['qty']; $exp = $_GET['exp']; $result = $db-&gt;getGameState($email, $monster, $qty, $exp); if (!empty($result)) { echo json_encode($response); } else { $response["error"] = 1; $response["error_msg"] = "Error getting game state from server"; echo json_encode($response); } </code></pre> <p>functions.php</p> <pre><code>public function getGameState($email, $monster, $qty, $exp) { $result = mysql_query("SELECT monster AND qty AND exp WHERE email = '$email'"); $row = mysql_fetch_assoc($result); if (mysql_num_rows($result) &gt; 0) { $gamestate = array(); $gamestate["monster"] = $result["monster"]; $gamestate["qty"] = $result["qty"]; $gamestate["exp"] = $result["exp"]; // success $response["success"] = 1; // user node $response["GameState"] = array(); array_push($response["GameState"], $gamestate); // echoing JSON response echo ($response); } else { return false; } </code></pre> <p>Here are some error messages I am receiving </p> <pre><code>06-12 14:15:52.046: E/JSON(10577): &lt;b&gt;Warning&lt;/b&gt;: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in &lt;b&gt;/home/content/40/8529140/html/webapps/monster/include/DB_Functions.php&lt;/b&gt; on line &lt;b&gt;145&lt;/b&gt;&lt;br /&gt; 06-12 14:15:52.046: E/JSON(10577): &lt;b&gt;Warning&lt;/b&gt;: mysql_num_rows() expects parameter 1 to be resource, boolean given in &lt;b&gt;/home/content/40/8529140/html/webapps/monster/include/DB_Functions.php&lt;/b&gt; on line &lt;b&gt;147&lt;/b&gt;&lt;br /&gt; 06-12 14:15:52.046: E/JSON(10577): {"tag":"get_game_state","success":0,"error":1,"error_msg":"Error getting game state from server"} 06-12 14:15:52.046: E/JSON Parser(10577): Error parsing data org.json.JSONException: Value &lt;br of type java.lang.String cannot be converted to JSONObject </code></pre> <p>Lastly please don't tell me that my php insecure <strong>I know this</strong> PHP is not my strong point and I am looking to get a test version up and running. <a href="http://php.net/manual/en/book.pdo.php" rel="nofollow">PDO</a> is on my development roadmap and will be implemented. </p> <p>Thanks.</p> <p><strong>UPDATE</strong>:</p> <p>After fixing the SQL statement to select from the proper table </p> <pre><code>06-12 15:03:48.216: E/JSON Parser(11427): Error parsing data org.json.JSONException: Value Array of type java.lang.String cannot be converted to JSONObject </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload