Search Unity

[Solved] MySQL save data

Discussion in 'Multiplayer' started by HolstP, Jan 17, 2017.

  1. HolstP

    HolstP

    Joined:
    Jan 17, 2017
    Posts:
    3
    Hey

    I just finished my login system using php and mysql and everyting is working just fine. When login is successful it loads up another scene. Now how do I recive the username of the user logged in so I can access the correct table in mysql and get other information about the user like (kill and death count)

    Thanks in advance
     
  2. Rosaki

    Rosaki

    Joined:
    Dec 1, 2016
    Posts:
    18
    I'm kind of puzzled by the question, as it requires a lot more information before it can be answered. First: How are you communicating from Unity to the database? Obviously through PHP, but... are you doing it from the client side or the server side? Or are you asking how to access the database from Unity at all?

    Next, wouldn't it be a matter of storing the name (Or other unique identifier) and reusing it as necessary? The rest would just be queries like I'm assuming you used to trigger a login system.
     
  3. HolstP

    HolstP

    Joined:
    Jan 17, 2017
    Posts:
    3
    Let me see if I can explain it a bit more.

    I have a login scene in Unity which has a username and password inputfield and there is a login button which has a login script on it that uses WWWForm to access the php script. now when the user has entered some valid user info it changes scene to the main menu.

    So my question is how do you store the users username so I can get the users info and for example display the username in other scenes and use the username to display other information about the user.

    If it was a website you would just use session_start when logging in and then use the session to fetch other information like...

    $sql = "SELECT *
    FROM users
    WHERE username = '" . $username . "'";

    I hope it's a bit more clear now :)
     
  4. Rosaki

    Rosaki

    Joined:
    Dec 1, 2016
    Posts:
    18
    The primary issue is going to be figuring out how to store it locally, which is the part I'm trying to figure out myself at this stage. However, fetching additional information will involve using WWWForm again, basically telling the PHP script what information you want and then return it back to Unity again. Communicating with the database is going to be a lot of communication from Unity to PHP, unless there's a better way to handle it that I haven't found yet.

    But, if you can figure out how to store it locally... just pass it into a [Command] function that requests more information. :)
     
  5. HolstP

    HolstP

    Joined:
    Jan 17, 2017
    Posts:
    3
    It's working just fine now.. took me a few hours but I got there. Storing the username across scenes was rather easy actually, where I had problems was when I was trying to fetch other data about that user :)
     
  6. Rosaki

    Rosaki

    Joined:
    Dec 1, 2016
    Posts:
    18
    Awesome. I'm just having trouble figuring out what's server and what's client-side and how to get the appropriate information exactly where I need it when I need it. Too much mixing for my overthinking mind to figure out.
     
unityunity