c# - Unity uploading player data text file to server, need some guide format

942

I need some guide in data format/syntax with php.

I have a simple form in my app, so user should fill the form and submit, Am successfully uploading my text file to my server, but need some good format.

Here is my code

[Header("Input Fields")]
public InputField userName;
public InputField mobileNo;
public InputField coinsToRedeem;
[Header("Data Strings")]
public string usernameText;
public string mobileNoText ;
public string coinsText;
public void GetSetData()
{
    usernameText = userName.text;
    mobileNoText = mobileNo.text;
    coinsText = coinsToRedeem.text;
    StartCoroutine(UpLoadUserData());
}
IEnumerator UpLoadUserData()
{ 
    WWWForm form = new WWWForm();
    form.AddField("name", usernameText);
    form.AddField("data", mobileNoText +","+ coinsText);
    UnityWebRequest www = UnityWebRequest.Post("https://myserver/UserData.php", form);
    yield return www.SendWebRequest();
    if (www.isNetworkError)
        Debug.Log(www.error);
    else
        Debug.Log("Uploaded");
}

PHP CODE

<?php    
    if(isset($_POST['name']) && isset($_POST['data'])){
        file_put_contents($_POST['name'].".txt", $_POST['data']);      
        echo "uploaded.";
    }else{
        echo "invalid file uploaded.";
    }  
?>

So now the data text file is uploading, and in the text i got the data like this format "Mobile Number, Number of coins"

But i need below format "Mobile Number number of coins" So, how can i write like this? Or how to add more fields? thanks.

39

Answer

Solution:

form.AddField("data", mobileNoText +","+ coinsText);

this is where you format your data as "Mobile Number, Number of coins"

if you change it to something like

form.AddField("data", mobileNoText + coinsText);

it will write Mobile Number number of coins.

People are also looking for solutions to the problem: ffmpeg - I can't upload a live video on instagram with api mgp25 in php

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.