WWW not working on my PHPs
Hello. I am new to this, and I have followed the wiki tutorial "Server side highscores" in order to create a leaderboard on my server. Everything seems fine until I try to send/get the data within Unity, neither of them working properly. When I try to send data, null values are sent instead; and when I try to get it, I receive a string with content similar to a HTML script (with 'body' etc., nothing related to what I should receive). Doing these manually work without a problem. Here are the scripts:
test_insert.php ) or die('Could not connect: ' . mysql_error()); mysql_select_db('') or die('Could not select database');
$id = mysql_real_escape_string($_GET['id'], $database);
$msgid = mysql_real_escape_string($_GET['msgid'], $database);
echo $id . "\t" . $msgid;
$query = "INSERT INTO test (id, msgid) VALUES('$id', '$msgid');";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
?>
test_display.php ') or die('Could not connect: ' . mysql_error()); mysql_select_db('') or die('Could not select database');
$query = "SELECT * FROM `test`";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$num_results = mysql_num_rows($result);
for($i = 0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
echo $row['id'] . ' ' . $row['msgid'] . '/';
}
?>
Unity C#: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class phpstufftesting : MonoBehaviour {
public string postinfolink = "http://***/test_insert.php?";
public string getinfolink = "http://***/test_display.php";
IEnumerator PostInfo(int id, string msgid){
string post_id = postinfolink + "id=" + id + "&msgid=" + WWW.EscapeURL (msgid);
Debug.Log (post_id);
WWW hs_post = new WWW (post_id);
yield return hs_post;
if (hs_post.error != null)
Debug.Log (hs_post.error);
}
IEnumerator GetInfo(){
WWW hs_get = new WWW (getinfolink);
yield return hs_get;
if (hs_get.error != null)
Debug.Log ("Error: " + hs_get.error);
string info = hs_get.text;
string[] each = info.Split ('/');
for (int i = 0; i < each.Length; i++)
Debug.Log (each [i]);
}
void Start () {
StartCoroutine (PostInfo (5, "hello"));
}
// Update is called once per frame
void Update () {
}
}
crossdomain.xml
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
Retrieving data from other websites (tested for images from Google) works. Also, since I am only experimenting, I am using a free hosting service, but I don't believe this could be the problem behind this.