- Home /
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
Your answer
Follow this Question
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