Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by zak666 · May 27, 2016 at 08:54 AM · scriptingbasicsmysqlphp

displaying results from MYSQL-PHP

Hi gang, wonderingg how you display mysql into ur texts after u retrieve it from your database? need to put it into variables for use in me game looked around haven't been able to get and answer that actually works. have got my Registery to work, having trouble reaving and displaying the data.

C# :

 private string UserLoginURL = "http://mysite.com/loggin.php";
     private string UserRegiesterURL = "http://mysite.com/register.php";
     public string user = "";
     public string pass = "";
     public string email = "";
 
     //fetched from mysql
     public Text XPText;
     public Image XPbar;
     public Text GoldText;
     public Text LevelText;
     public Text UsernameText;
     public Text RankText;
     public Text Recorcess;
 
     //saveforsession:
     public Text UserSession;
     public Text PassSession;
 
     //setactive when loggedin
     public GameObject Logedin;
     public GameObject Logedout;
     public GameObject AccountSucsess;
     public GameObject IncorreectUsernamePass;
     //input by player
     public Text InputUsername;
     public Text InputPassword;
     public Text InputEmail;
 
 
     //------------------------------------------------------------------------------------
 
     public void Loggin()
     {
         user = InputUsername.text;
         pass = InputPassword.text;
         Debug.Log ("" + user + pass + email); // make sure string is acualy their.
         StartCoroutine(LoginUser(user, pass));
     }
 
     //------------------------------------------------------------------------------------
 
 
     public void Register()
     {
         user = InputUsername.text;
         pass = InputPassword.text;
         email = InputEmail.text;
         StartCoroutine(RegisterUser(user, pass, email));
         Debug.Log ("" + user + pass + email); // make sure string is acualy their.
 
 
     }
 
     //------------------------------------------------------------------------------------
 
     IEnumerator LoginUser(string User, string Pass ) {
         WWW Login = new WWW (UserLoginURL +  "?user=" + user + "?pass=" + pass);
         yield return Login;
         if (Login.success=="true") {
             var gold = Login.Gold;
             var Recourses = Login.Recourses;
             var Xp = Login.Xp;
             var Rank = Login.Rank;
             var Level = Login.Level;
             Logedin.SetActive (true);
             Logedout.SetActive (false);
         } else {
             // Could not find the user/password combination
             IncorreectUsernamePass.SetActive (true);
 
         }
     }
 
     //------------------------------------------------------------------------------------
 
 
     IEnumerator RegisterUser(string user, string pass, string email ) {
         WWW Register = new WWW (UserRegiesterURL + "?user=" + user + "?pass=" + pass + "?email=" + email);
         yield return Register;
         if (Register.error == null) {
             AccountSucsess.SetActive (true);
             Debug.Log ("account Created" + Register.text); // show me the echo
 
         } else {
             Debug.Log ("Error" + Register.text); // show me the echo
 
         }
     }
 
 } // END OF CLASS     //--------------------------------------------------------------------
 






PHP:

 <?
     require_once("..php");
 
     // Create connection
     $mysqli = new mysqli($server, $serverUser, $serverPass, $database);
     if ($mysqli->connect_error) {
         die('Connect Error ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
     }
 
     $response = array();
 
     $query = sprintf("SELECT txtUsername, txtPassword FROM tbl_user WHERE txtUsername = '%s' AND  txtPassword = '%s'",
         $mysqli->real_escape_string($_GET['user']),
         $mysqli->real_escape_string($_GET['pass'])
     );
     $result = $mysqli->query($query) or die("Unable to select database");
 
     if ($mysqli->affected_rows > 0) {
         $userData = $result->fetch_assoc();
         $response['Success'] = "true";
         $response['Gold'] = $userData['Gold'];
         $response['Recourses'] = $userData['Recourses'];
         $response['Xp'] = $userData['Xp'];
         $response['Rank'] = $userData['Rank'];
         $response['Level'] = $userData['Level'];
     } else {
         $response['Success'] = "false";
     }
 
     echo json_encode($response);
 
     $mysqli->close();
 
 ?>

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

43 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

iOS and MySQL : PHP or .NET Plugin ? 0 Answers

Player score update with PHP MySQL 1 Answer

A personal server for my multiplayer using MySQL 0 Answers

Internetconnection without php 0 Answers

C # Does not recognize characters after space 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges