我尝试在 codeigniter 中使用 rest api 来插入数据。
我试试这个
public function sensor_post(){
$data = array(
'sensor_id' => $this->input->post('sensor_id'),
'value' => $this->input->post('value'));
$insert = $this->db->insert('measurement', $data);
if ($insert) {
$this->response($data, 200);
} else {
$this->response(array('status' => 'fail', 502));
}
}
并调用 http://localhost/rest_iot/index.php/iot/sensor?sensor_id=1&value=37
我在邮递员中尝试这样做,但出现这样的错误。我想我已经填满了价值,为什么会这样?
<h1>A Database Error Occurred</h1>
<p>Error Number: 1048</p>
<p>Column 'sensor_id' cannot be null</p>
<p>INSERT INTO `measurement` (`sensor_id`, `value`) VALUES (NULL, NULL)</p>
<p>Filename: C:/xampp/htdocs/rest_iot/system/database/DB_driver.php</p>
<p>Line Number: 691</p>
米琪卡哇伊
阿晨1998
慕田峪4524236