- Home /
Send Data From C# to PHP Server
Any one has an idea why this is not working?
C# code in unity
WWWForm form = new WWWForm();
form.AddField("tablenamepost", "furniture");
WWW www = new WWW(url, form);
PHP code server
if(isset($_POST["tablenamepost"])) {
echo $POST["tablenamepost"];
}
else echo "error";
i always get "eror" when refreshing the url since nothing its coming from unity....the url its fine.
Do you actually read the return value inside Unity? Do you do your WWW call in a coroutine?
Also note that you check if "$_POST...." is set but then you use "$POST....". $$anonymous$$aybe you setup your server wrong so it might not create certain globals depending on the PHP config.
You haven't provided enough information so we can't give you an exact answer. There are by far too many "unknown variables" here.
ps: If you want to improve your question, feel free to edit it by pressing the little "cogwheel" at the top right of your question and select "edit".
Thank you for your response, i fixed the "$POST" issue in the php file
"$$anonymous$$aybe you setup your server wrong so it might not create certain globals depending on the PHP config" - i dont think so because im able to get data from the server.
Now i added a corroutine and i have something like this but stills not working :(
void Start () {
WWWForm form = new WWWForm();
form.AddField("tablenamepost", "furniture");
WWW www = new WWW(url, form);
StartCoroutine(WaitForRequest(www));
}
IEnumerator WaitForRequest(WWW www)
{
yield return www;
// check for errors
if (www.error == null)
{
Debug.Log("WWW Ok!: " + www.data);
}
else
{
Debug.Log("WWW Error: " + www.error);
}
}
Did you make a var_dump of $_POST (or if it's too big a print_r) and see what $_POST actually contains? I don't have experience with the unit WWWForm class, but how do you know the value isn't set as a GET-parameter? Did you look in $_GET if it exists there? Is the php script actually printing anything? And is the webserver the script is running on configured correctly?
I would recommend you to create a soap or rest service for those tasks.
Your answer
![](https://koobas.hobune.stream/wayback/20220612094547im_/https://answers.unity.com/themes/thub/images/avi.jpg)