[英]PHP not inserting data in mysql table
真正簡單的代碼
$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
。
也沒有錯誤報告。
$device1 = $_GET['device'];
$device = "device".$device1;
mysqli_query($connect, "insert into '".$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);");
要么
mysqli_query($connect, "insert into device".$device." (time, voltage, current, power) values (curtime(), $voltage, $current, $power);");
因為$device
是一個整數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.