html数组通过php

时间:2017-01-27 19:32:28

标签: php python html arrays

我尝试将数据从数组中的html输入通过php部分传递给python脚本。这个脚本在按钮点击时执行,只是将其参数写入txt文件。

html部分:

<input type="number" id="Uhrzeit_mo" name="day[]" value="" Maxlength="5" size="4">
<a href="?id=schedule" target="_parent"><button>Senden</button></a>

php部分:

<?php
if (isset($_GET["id"])) {
    $id = $_GET["id"];
    if($id == "button_on") {
        shell_exec("sudo /var/www/gpiotest2.py 3");
    } elseif($id == "schedule") {
        $day = $_POST['day'][0];
        $day2 = 6;
        shell_exec("sudo /var/www/params.py {$day} {$day2}");
    }
}
?>

如果执行,第一个条件语句可以正常工作。第二个没有。 $ day不会写入文本文件,我不知道为什么。

更好的调试的其他问题:有没有办法重定向错误消息,因为当通过按钮单击触发脚本时,我的putty终端保持为空。顺便说一下scipt本身工作正常。 非常感谢!

1 个答案:

答案 0 :(得分:0)

您在此行中缺少MaxLength附近的引号: <input type="time" id="Uhrzeit_mo" name="day[]" value="10:00" Maxlength=5" size="4">

这肯定会改变变量传递的内容。

至于PHP。在第二个条件中,添加一个'else'语句,其中包含一个警告框,其中列出了您变量的值。看起来你没有得到你认为你得到的价值。