Android and mysql?

0 favourites
  • 14 posts
  • 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.

  • You can use an Ajax request to an url with a PHP file.

  • And I can export with intels xdk/android and it will work?

  • Yes it will.

  • Yup, it will, I can confirm. Square Eater uses Ajax and it works without problems. http://bit.ly/1wKDiNT

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Sounds like an error in your php.

    If you paste the bits involved, I can perhaps assist.

  • <?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();
    ?>[/code:qbzr854i]
    
    Here is what I have 
    [img="http://i.imgur.com/7mTP33I.png"]
    
    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
  • I decided to include my event page for the first page (the login layout)

    and the full even sheet for the score sending. The first AJAX request works fine. It just echos table data though.

  • mysql_query("UPDATE members   SET score = '".$score."'  WHERE id = '".$uid."' ");
    
    [/code:2t41ttil]
    
    change to
    
    [code:2t41ttil]
    	$sql = "UPDATE members   SET score = $score  WHERE id = $uid ";
    		$result = mysql_query($sql);
    		if (!$result) {
    		echo mysql_error();
    		exit;
    		}
    [/code:2t41ttil]
    
    Now, if you get an error with your php, it shows in the Ajax.LastData
  • There is an error here

    "uid="&UserID&"&score="&score

    You missed an & there

  • I get error:

    -------------

    Warning: mysql_query() [function.mysql-query]: Access denied for user '3ixteam'obv@'localhost' (using password: NO) in /home/eponaonl/public_html/logintest/update.php on line 16

    Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/eponaonl/public_html/logintest/update.php on line 16

    Access denied for user '3ixteam'obv@'localhost' (using password: NO)

    ------------------

    with this code

    ----------------------------------

    <?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);
    } 
    $sql = "UPDATE members   SET score = $score  WHERE id = $uid ";
          $result = mysql_query($sql);
          if (!$result) {
          echo mysql_error();
          exit;
          }
    
    $conn->close();
    ?>[/code:9cbr76xc]
    
    [img="http://i.imgur.com/b5sWMjM.png"]
  • If you are sure you are using the correct password

    You could try

    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    [/code:27b1ol1a]
    
    change to 
    
    [code:27b1ol1a]
    	$conn = mysql_connect($servername, $username, $password);            
    	if (!$conn) { 
    		die('Could not connect to MySQL: ' . mysql_error()); 
    	}
       
         $result = mysql_select_db($dbname); 
         if(!$result){
            echo mysql_error();
            exit;
       }
    
    [/code:27b1ol1a]
    
    EDIT:   user  "3ixteam"  , is not what your php file shows
  • I'm not sure what that error is all about. I lokked up about 3 other errors that I got after fixing that one. Then there was ne on line 26. I commented out the connection close and it works now so I'm not sure what did it. Oh annnddd I also screwed up and chmodded the wrong file when I shouldn't have done it at all. Yep. Derp. That was just one of many issues. I wouldn't have even started to scratch the surface of what the problem was unless you guys hadn't helped me. Thanks so much. I wish I could buy you a round.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)