Unity c#POST到PHP无法正常工作

I'm having a really annoying problem with php. With c# I send variables to php, and I want php to save it into my database. But the $_POST in php is empty. In Unity I did a Debug.Log of the variables I am sending to php right before it sends to see if it works, and the variables are there. BUT in php when I echo the $_POST, it returns nothing, it's empty and in the database it adds emptiness.

Update: I added an if statement on the php code to see if the post variables are empty, say, it's empty, if they are not empty, update them in the database. BUT it keeps saying the variables are empty. I need to finish this project in 3 days and this is the only problem that I have to fix and I'm done, please help.

c#:

public IEnumerator replaceData(string toggle1Post, string toggle2Post, 
                                string toggle3Post, string toggle4Post,
                                string toggle5Post, string toggle6Post)
 {
     WWWForm form = new WWWForm();


     form.AddField("toggle1Post", toggle1Post);

     form.AddField("toggle2Post", toggle2Post);

     form.AddField("toggle3Post", toggle3Post);

     form.AddField("toggle4Post", toggle4Post);

     form.AddField("toggle5Post", toggle5Post);

     form.AddField("toggle6Post", toggle6Post);

     WWW www = new WWW(parkingURL, form);

     yield return www;

     Debug.Log(www.text);
 }

php:

//Make the connection_aborted
$conn = new mysqli($server_name, $server_username, $server_password, $dbName);

//Check connection_aborted
if (!$conn)
{
    die("Connection Failed. ". mysqli_connect_error());
}
else 
{
    //echo("Connection Success" . "<br>");
}

$parkingName1 = "Bus Gate";
$toggle1Post = $_POST['toggle1Post'];

$parkingName2 = "Pepsi Gate";
$toggle2Post = $_POST['toggle2Post'];

$parkingName3 = "Watson";
$toggle3Post = $_POST['toggle3Post'];

$parkingName4 = "PVA";
$toggle4Post = $_POST['toggle4Post'];

$parkingName5 = "Gardens";
$toggle5Post = $_POST['toggle5Post'];

$parkingName6 = "Omar Mohsen";
$toggle6Post = $_POST['toggle6Post'];


if ($toggle1Post != "" || $toggle2Post != "" || $toggle3Post != "" || $toggle4Post != "" || $toggle5Post != "" || $toggle5Post != "")
{
    $sql1 = "UPDATE parking SET Toggle = '$toggle1Post' WHERE gateName = '$parkingName1'";

    if (mysqli_query($conn, $sql1)) echo " Updated " . $toggle1Post;
    else echo "notUpdated: " . mysqli_error($conn);

    $sql2 = "UPDATE parking SET Toggle = '$toggle2Post' WHERE gateName = '$parkingName2'";

    if (mysqli_query($conn, $sql2)) echo " Updated " . $toggle2Post;
    else echo "notUpdated: " . mysqli_error($conn);


    $sql3 = "UPDATE parking SET Toggle = '$toggle3Post' WHERE gateName = '$parkingName3'";

    if (mysqli_query($conn, $sql3)) echo " Updated " . $toggle3Post;
    else echo "notUpdated: " . mysqli_error($conn);


    $sql4 = "UPDATE parking SET Toggle = '$toggle4Post' WHERE gateName = '$parkingName4'";

    if (mysqli_query($conn, $sql4)) echo " Updated " . $toggle4Post;
    else echo "notUpdated: " . mysqli_error($conn);


    $sql5 = "UPDATE parking SET Toggle = '$toggle5Post' WHERE gateName = '$parkingName5'";

    if (mysqli_query($conn, $sql5)) echo " Updated " . $toggle5Post;
    else echo "notUpdated: " . mysqli_error($conn);


    $sql6 = "UPDATE parking SET Toggle = '$toggle6Post' WHERE gateName = '$parkingName6'";

    if (mysqli_query($conn, $sql6)) echo " Updated " . $toggle6Post;
    else echo "notUpdated: " . mysqli_error($conn);
}
else
{
    echo "The variable is empty ";
}

Update 2: I tried the same code on another computer with unity version 5.4.1f1 and it worked there, on my computer I'm on version 2017.3.0f3 and it does not work.

dongliao1948
dongliao1948 对不起,我忘了发布php代码的第一部分,我刚刚更新了
2 年多之前 回复
douyou1901
douyou1901 你知道你需要引用$_POST超全局中的密钥,例如$_POST['toggle1Post'],对吧?像$toggle1Post这样的变量不会自动定义。
2 年多之前 回复
doumiang0597
doumiang0597 看起来你错过了PHP脚本中你用$_POST做任何事情的部分。你能在这里展示一下吗?
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐