display data from mysql
i want show $_POST username from mysql db in unity 3d text mesh sry for english i have login system and he work my code:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class database : MonoBehaviour
{
public static string username = "", name = "";
private string password = "", rePass = "", message = "";
public bool isSuccess= false;
private bool register = false;
private void OnGUI()
{
if (message != "")
GUILayout.Box(message);
if (register)
{
GUILayout.Label("Username");
username = GUILayout.TextField(username);
GUILayout.Label("Name");
name = GUILayout.TextField(name);
GUILayout.Label("password");
password = GUILayout.PasswordField(password, "*"[0]);
GUILayout.Label("Re-password");
rePass = GUILayout.PasswordField(rePass, "*"[0]);
GUILayout.BeginHorizontal();
if (GUILayout.Button("Back"))
register = false;
if (GUILayout.Button("Register"))
{
message = "";
if (username == "" || name == "" || password == "")
message += "Please enter all the fields \n";
else
{
if (password == rePass)
{
WWWForm form = new WWWForm();
form.AddField("username", username);
form.AddField("name", name);
form.AddField("password", password);
WWW w = new WWW("http://f6-preview.awardspace.com/unitytutorial.com/register.php", form);
StartCoroutine(registerFunc(w));
}
else
message += "Your Password does not match \n";
}
}
GUILayout.EndHorizontal();
}
else
{
GUILayout.Label("User:");
username = GUILayout.TextField(username);
GUILayout.Label("Password:");
password = GUILayout.PasswordField(password, "*"[0]);
GUILayout.BeginHorizontal();
if (GUILayout.Button("Login"))
{
message = "";
if (username == "" || password == "")
message += "Please enter all the fields \n";
else
{
WWWForm form = new WWWForm();
form.AddField("username", username);
form.AddField("password", password);
WWW w = new WWW("http://localhost/tester/login.php", form);
StartCoroutine(login(w));
}
}
if (GUILayout.Button("Register"))
register = true;
GUILayout.EndHorizontal();
}
}
IEnumerator login(WWW w)
{
yield return w;
if (w.error == null)
{
if (w.text == "login-SUCCESS")
{
isSuccess = true;
}
else
message += w.text;
}
else
{
message += "ERROR: " + w.error + "\n";
}
}
IEnumerator registerFunc(WWW w)
{
yield return w;
if (w.error == null)
{
message += w.text;
}
else
{
message += "ERROR: " + w.error + "\n";
}
}
void Update (){
if(isSuccess == true){
SceneManager.LoadScene("haha");
}
}
}
and my usernameshow code,plss help me, i put usernameshow in text mesh
using UnityEngine;
using System.Collections;
using System.Text.RegularExpressions;
public class usernameshow : MonoBehaviour {
public static string username = "";
// Use this for initialization
void OnGUI () {
string url = "http://localhost/tester/login.php";
WWW www = new WWW (url);
StartCoroutine (registerFunc (www));
GetComponent<TextMesh>().text = username;
}
IEnumerator registerFunc(WWW www)
{
yield return www;
username = www.text;
}
// Update is called once per frame
void Update () {
}
}
Comment
You should at least explain what's working and what's not.
username from mysql dont display in textmesh after login