I’ve been trying to work out the details of sending a simple int variable to display on a website I manage. I can’t tell if I’m bypassing something essential in this process (like setting up a more complicated server), but I’ve been trying to get WWWForms to work and can’t get it to display the variable online correctly.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class WWW_output : MonoBehaviour {
void Start () {
int num;
num = 12;
string url = "http://myurl/test.php";
WWWForm form = new WWWForm ();
form.AddField("var_1", num.ToString());
WWW www = new WWW (url, form);
StartCoroutine (Upload (www));
}
IEnumerator Upload(WWW www){
yield return www;
if (www.error == null){
Debug.Log (www.text);
}
else{
Debug.Log ("unable to update data:" + www.error);
}
}
}
However, when I run the game the information parses correctly and I can see the www.text to display correctly in Unity’s console. I’d really like to make sure that I can also just simply display the num.ToString in the browser as well. So I just tried running a simple php template:
<!DOCTYPE HTML>
<HTML>
<BODY>
<?php echo $_POST["var_1"] ?>
</BODY>
</HTML>
But no avail… Any thoughts?