- Home /
The question is answered, right answer was accepted
www.text + php + c# issue
I’m testing the WWW class functionality but I’m having problems to retrieve the data from the server. Since posting data is ok, I'll skip that bit.
On the server side, unityOut.php
<?php
$sql = "SELECT * FROM unity ORDER BY cod_user DESC";
$consulta = mysql_query($sql, $conexion);
while($reg = mysql_fetch_array($consulta)){
echo $reg["name"];
echo $reg["extra_field"];
}
?>
That code connects with DB ok, since I can look for the website and see it on the browser:
Now, on the Unity C# side, I want to retrieve that data:
public string url = "http://...url.../unityOut.php";
private WWW www;
void OnGUI ( ) {
if (GUI.Button(new Rect(8*unitW, 5*unitH, 8*unitW, 2*unitH), "Get data")){
StartCoroutine("getData");
}
}
IEnumerator getData(){
www = new WWW(url);
yield return www;
Debug.Log("hello: " + www.text);
}
}
}
I'm ok with parsing whatever it comes, but, at this moment... All I get for www.text is the html label. Any clues of what am I missing?
Thanks
note, it is incredibly unlikely anyone will answer a question with so much long code
also this is really just a php setver question. consider stackoverflow? the weenies on that site will give you many long answers immediately :)
I have this same problem, even copying directly over from a working JS code. It must be something in C# that needs to be different because none of these answers on Unity Answers work for me!
Answer by jaybennett · May 18, 2013 at 10:18 AM
I have this same problem, even copying directly over from a working JS code. It must be something in C# that needs to be different because none of these answers on Unity Answers work for me!
Answer by biohazard2u · May 18, 2013 at 10:35 AM
My problem, in the end, had nothing to do with coding; all it was is that I was forgetting to refresh a URL so I was always running the old code. My advice, make sure you have updated all your php files on the server. Also, if you have a public URL string storing the URL to collect/send data, make sure that any changes on the code are happening on the Inspector too.