how can i save score and name into free webhost...?

i think theirs  a problem of this…

 

local playerName = “sos”
local playerscore = 200

local URL = “http://1dermindstudios.comyr.com/submitscore.php?playername=” …(playerName) … “&playerscore=” …(playerscore)
network.request( URL, “GET”, networkListener

I would add a:

print_r($_GET); 

just before the if(isset($_GET) line.  Then put

echo($playername);

echo($playerscore);

after you set those variables.  Finally do a:

echo($query);  

just before you call mysql_query($query).  You can run this in your browser to make sure its working.  In your Corona App, print your URL value just before you call network.request().  Copy that URL to a web browser’s location bar to run your script fro the browser to see  your output.

Rob

sir same like this?

 <?php

print_r($_GET);

if(isset($_GET)) {

echo($playername);
echo($playerscore);

    $playername =  ($_GET[“playername”]);
    $playerscore = ($_GET[“playerscore”]);

        
        $query = ‘INSERT INTO player (playername,playerscore) VALUES ("’.mysql_real_escape_string($playername).’","’.mysql_real_escape_string($playerscore).’")’;
        $result = mysql_query($query);
        echo json_encode($result);
        echo($query);
        }
        exit
?>
 

but why output same like this…?

 

Array() trueINSERT INTO player (playername,playerscore) VALUES ("","")

theirs no value inserted

this is my Main.lua

 
local myNewData
local json = require (“json”)
local decodedData

local playerName = “sos”
local playerscore = 200

local function networkListener( event )
        if ( event.isError ) then
                print( “Network error!”)
        else
                myNewData = event.response
                print ("From server: "…myNewData)
                decodedData = (json.decode( myNewData))

        end
end
local URL = “http://1dermindstudios.comyr.com/submitscore.php?playername=” …(playerName) … “&playerscore=” …(playerscore)
network.request( URL, “GET”, networkListener )

 

problem solve… yehey tnx sir rob :slight_smile:

sir ROB… why the out put of this… is delay… its normal?

local function networkListener( event )
        if ( event.isError ) then
                print( “Network error!”)
        else
                myNewData = event.response                           --------------------------------------------------------------------
                print ("From server: "…myNewData                     -----------IN THIS PART DELAY OUTPUT----------------
                decodedData = (json.decode( myNewData)) ---------------------------------------------------------------------

        end
end
local URL = “http://1dermindstudios.comyr.com/submitscore.php?playername=” …(playerName) … “&playerscore=” …(playerscore)
network.request( URL, “GET”, networkListener )

:slight_smile:

It has to get a response from the server first, so depending on the speed of the server and the amount of data being returned, the speed of the response will vary.

You should read up on networking before jumping in to the deep end :wink:

i use to have code that this. i never completed it, it only saved name and score but there was no login process or unique user names. i’ll see if i can find it

Generally speaking, you’re going to  have to setup a database on your host, most likely MySQL to have the necessary tables to track the data you want to save and retrieve.   Next you will need to write some server side code in a language like PHP or Python that can communicate with the database and yet still output data to web requests.  The scripts that do this would have a URL like:

http://yourhost.com/yourapp/getscore.php

If you created a script called getscore.php that talked to the database.  In Corona SDK you then use the network.request() API to get the data, something like:

network.request(“http://yourhost.com/yourapp/getscore.php”, “GET”, callbackListener)

Where callbackListener is a function that handles getting the results of the call back into your app.  You would be responsible for managing any security needs for your server and database.  Your scripts would need to be hack proof (no SQL injections, no clearly visible passwords, one way encrypted password hashes on the server side.

If you’ve never done this before and don’t have experience with network programming, Corona SDK offers several plugins for doing this, like PlayTogether as well as using Google Play Game Services or Apple’s GameCenter to track leaderboards for high scores.   Several people in the community have been putting together an easy to use Parse.com setup if you want more database flexibility.  You would need to search the forums for parse to find those threads.

Rob

I recommend the play store api it save your scores to a sever and check it for you. Every easy try it

I recommend the play store api it save your scores to a sever and check it for you. Every easy try it

yes sir… ders no log-in process… it save name and score only…

hope u find it… tnx

i have already created a database in my free webhost… table name ‘player’ 2 fields only  ‘name’ and ‘score’.
but i dont know how to connect it corona … i dont havent experience of network programming so i ithink i use plug-ins…

can you give a link sir for tutorials… ?

https://coronalabs.com/blog/2013/06/25/tutorial-introducing-google-play-game-services/ hope this help any questions ask me I am here. Happy coding …:slight_smile:

https://play.google.com/store/apps/details?id=com.boxingstudiogames.jetfighter use my game as guide hope this help

I wrote this long before I came to Corona Labs:  http://omnigeek.robmiracle.com/2012/04/15/using-corona-sdk-with-rest-api-services/

That should get you started.

Rob

sir Rob? can i access the mysql database of my free webhost into the corona without using php…?
because no need to view the score and the web. its only in the device… 

i think ur familiar this…

$mysql_host = “mysql6.000webhost.com”;
$mysql_database = “a9679956_TR1”;
$mysql_user = “a9679956_ian”;
$mysql_password = “juario0123”;

–sir ROB when i access the webserver  using this…

network.request( “http://mysite.com/api/login.php?playername=” … mime.b64(username) … “&password=” … mime.b64(password), “GET”, callback )

–then in the php file.

if(isset($_GET)) {
    $playername = base64_decode($_GET[“playername”]);
    $password = base64_decode($_GET[“password”]);
}

then where is the part  to save the the ‘NAME’ of the Player and ‘Score’?

example after the game…

he input the name ‘IAN’ then he’s score is ‘100’…

how can i do that?