duan2891 2018-02-13 18:39
浏览 81

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.

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
    • ¥15 安装svn网络有问题怎么办
    • ¥15 Python爬取指定微博话题下的内容,保存为txt
    • ¥15 vue2登录调用后端接口如何实现
    • ¥65 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)