非常简单的代码
$device = $_GET['device'];
$voltage = $_GET['voltage'];
$current = $_GET['current'];
$power = $current * $voltage;
mysqli_query($connect, "insert into device$device (time, voltage, current, power)
values (curtime(), $voltage, $current, $power);");
问题是,它曾用于处理我放置的任何设备号。它只适用于设备1.没有使用mysql数据库或php代码进行任何更改,它突然不再起作用了,除非是$device=1
。
也没有报告任何错误。
答案 0 :(得分:0)
$device1 = $_GET['device'];
$device = "device".$device1;
mysqli_query($connect, "insert into '".$device." (time, voltage, current, power)
values (curtime(), '$voltage', '$current', '$power')");
更改查询
答案 1 :(得分:0)
mysqli_query($connect, "insert into device'".$device."' (time, voltage, current, power)
values (curtime(), $voltage, $current, $power);");
或
mysqli_query($connect, "insert into device".$device." (time, voltage, current, power) values (curtime(), $voltage, $current, $power);");
因为$device
是一个int号。