Request username from database

0 favourites
  • 3 posts
From the Asset Store
Basic Plugins for Firebase Authentication, Realtime-Database, Firestore, Cloud Storage
  • Hi Guys,

    Im working on a Highscore system.

    But i want my website users to have their name and profile picture in my games, when they are logged in to my website.

    How would i "get" username and/or image from a database?

    Is it done through ajax or something completely else?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Short answer: Yes.

    Longer version:

    This scirra.com/tutorials/346/online-high-score-table-ajax-php-mysql tutorial will give you basic information, you can modify script for your needs.

    Example call:

    "http://website.com/get.php?name="&name

    note: after name=" you should define where script looks for name, it can be global variable, instance variable or so. To get information out, I had following line in my PHP script

    $result = mysql_query("SELECT * FROM (table) WHERE (row) = '" . mysql_real_escape_string($_GET['name']) . "'");
    $row = mysql_fetch_row($result);

    (table) = name of database table.

    (row) = row where to look for info.

    Example

    $result = mysql_query("SELECT * FROM highscores WHERE name = '" . mysql_real_escape_string($_GET['name']) . "'");
    $row = mysql_fetch_row($result);

    In this script is looking from highscores table and checking "name" row to match player name and gets information from there. Then we want some data out from player mysql rows. We can do following

    $koe = stripslashes($row[3]);
    echo $koe;

    This would echo $koe value to browser which you can echo to game using "Ajax.LastData" method. So whats up with $koe? In "$koe = stripslashes($row[3])" line Im looking third row from database, here is

    example setup:

    highcores table: ID, name, score.

    now when we look at this, "score" is third row which is why we echoed it since we wanted score.

    At websites (where we we have this script) we echoed $koe Ajax.LastData got one value which was $koe (score from database). You can use this method to dig out information from database to your game, modify script for your needs. To save up some time, you can also do few if/elseif things in script to define what exactly script is looking.

    Example

    "http://website.com/get.php?pid=score&name="&name

    example code at PHP page.

    <?php if $_REQUEST["pid"] == "score") { mysql code for score search };
    elseif ($_REQUEST["pid"] == "avatar") { mysql code for avatar search ; }?>

    Now you have to only change "pid=score" line from ajax request to match score or avatar and your PHP script would echo information you need without need to setup more complex thing. To get image, I assume you could echo full URL, for example check this file: dl.dropbox.com/u/59009902/load_image_from_url.capx

    Hopefully this helps abit, I assume you wanted more simple and short answer but I figured that small tutorial would help others who are looking for answer to same problem.

    This is not perfect solution but worked for me, tho I was searching and taking larger amount of data but idea is same. Feel free to send me private message if you need more detailed help.

  • A very helpful & simplified explanation CoffeeOD ! Thank you! <img src="smileys/smiley1.gif" border="0" align="middle" />

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