PHP不在mysql表中插入数据

时间:2017-01-19 05:40:11

标签: php mysql

非常简单的代码

$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

也没有报告任何错误。

2 个答案:

答案 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号。