Android and mysql?

Get help using Construct 2

Post » Wed Apr 15, 2015 5:42 pm

Is there a way to keep track of user points on the web for android applications? I have my own server, plenty of mysql dbs, I know how to configure php scripts... but I seem to have read that this isn't possible. If it is, I'm having trouble finding info on it. I want to export using cordova and build with android crosswalk. I'm using intels XDK currently.
B
10
S
5
G
4
Posts: 23
Reputation: 2,923

Post » Thu Apr 16, 2015 6:25 pm

You can use an Ajax request to an url with a PHP file.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Sat Apr 18, 2015 4:44 am

And I can export with intels xdk/android and it will work?
B
10
S
5
G
4
Posts: 23
Reputation: 2,923

Post » Sat Apr 18, 2015 6:11 am

Yes it will.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Sun Apr 19, 2015 2:49 pm

Yup, it will, I can confirm. Square Eater uses Ajax and it works without problems. http://bit.ly/1wKDiNT
B
32
S
7
G
4
Posts: 398
Reputation: 4,591

Post » Sun Apr 19, 2015 5:47 pm

Thanks, I really appreciate the response :). I'm still struggling with updating my db with ajax requests. I can login, pull up table data... but can't seem to write to the db based on user id
B
10
S
5
G
4
Posts: 23
Reputation: 2,923

Post » Sun Apr 19, 2015 5:53 pm

Sounds like an error in your php.

If you paste the bits involved, I can perhaps assist.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Sun Apr 19, 2015 7:34 pm

Code: Select all

<?php
$uid = $_POST['uid'];
$score = $_POST['score'];
$servername = "localhost";
$username = "eponaonl_admin";
$password = "****";
$dbname = "eponaonl_horse";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
mysql_query("
    UPDATE members
    SET score = '".$score."'
    WHERE id = '".$uid."'
");

$conn->close();
?>


Here is what I have
Image


Obviously just starred out the pass in the code.

UserID is a global variable in C2 and was defines on login on layout before. score is a global variable that is updated every tick. Thats what I want to pass into the table based on what the id is. Id is auto increment in the table
B
10
S
5
G
4
Posts: 23
Reputation: 2,923

Post » Sun Apr 19, 2015 7:41 pm

I decided to include my event page for the first page (the login layout)
Image

and the full even sheet for the score sending. The first AJAX request works fine. It just echos table data though.
Image
B
10
S
5
G
4
Posts: 23
Reputation: 2,923

Post » Sun Apr 19, 2015 8:08 pm

Code: Select all
mysql_query("UPDATE members   SET score = '".$score."'  WHERE id = '".$uid."' ");



change to

Code: Select all
   $sql = "UPDATE members   SET score = $score  WHERE id = $uid ";
      $result = mysql_query($sql);
      if (!$result) {
      echo mysql_error();
      exit;
      }



Now, if you get an error with your php, it shows in the Ajax.LastData :)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 19 guests