I am trying to save user scores into my data base so i have deveoped backend on php and mysql datbase. All the things are complete but having issues to send or receive data through my unity WWW class.
Here is my C# code to get and send data to php and then DB:
using UnityEngine;
using System.Collections;
public class Scripts : MonoBehaviour {
string dataSubmitURL = "http://localhost/HighScore/AddScore.php?";
string dataGetURL = "http://localhost/HighScore/GetScore.php";
// Use this for initialization
void Start () {
StartCoroutine(GetScores());
//StartCoroutine(PostScores("faizan",100));
}
// Update is called once per frame
void Update () {
}
IEnumerator PostScores(string playerName, int score) {
string submitURL = dataSubmitURL + "name="+ playerName + "&score=" + score;
print(submitURL);
WWW submitData = new WWW(submitURL);
yield return submitData;
if (submitData.error != null)
{
Debug.LogError("Error occur when Submitting data : " + submitData.error);
Debug.LogError("Error occur when Submitting data : " + submitData.text);
Debug.LogError("Error occur when Submitting data : " + submitData.responseHeaders);
//submitData.text
}
else {
print(" Submitted");
}
}
IEnumerator GetScores() {
WWW getData = new WWW(dataGetURL);
yield return getData;
if (getData.error != null)
{
Debug.LogError("There was an error getting the high score: " + getData.error);
}
else {
print(getData.text);
}
}
}
If i directly run my urls into browser
string dataGetURL = "http://localhost/HighScore/GetScore.php";
then it is working perfectly and giving me data but same thing when i trying through my c# www(above code) then it reply.
There was an error getting the high score: Empty reply from server
yield return getData
. I believe you should just be usingyield getData
. \$\endgroup\$