未捕获的PDOException:SQLSTATE [23502]:不为null违反:7错误: 列“ id”中的空值违反了非空约束DETAIL:失败 行包含(null,null,null,null)。在 C:\ xampp \ htdocs \ ims \ app \ models \ CMP999 \ CMP999.php:80堆栈跟踪:#0 C:\ xampp \ htdocs \ ims \ app \ models \ CMP999 \ CMP999.php(80): PDOStatement-> execute()#1 C:\ xampp \ htdocs \ ims \ app \ controllers \ Compliance \ CMP999Controller.php(116): CMP999-> addData(true)#2 C:\ xampp \ htdocs \ ims \ app \ core \ App.php(146): CMP999Controller-> add('Compliance','CMP999','add')#3 C:\ xampp \ htdocs \ ims \ public \ index.php(7):App-> __ construct()#4 {main} 在第80行上的C:\ xampp \ htdocs \ ims \ app \ models \ CMP999 \ CMP999.php中抛出
嗨……我试图从网络插入数据并显示在表格中……但是当我尝试插入数据时,我遇到了这个错误…… php pdo使用mvc并使用postgresql数据库。...这是我的一些相关代码
// CMP999.php models
public function addData($data) {
// $data = print_r($_POST);
// die();
$query = $this->pdo->prepare('INSERT INTO test( id , name, ic, qualification) VALUES ( :id, :name, :ic, :qualification)');
//$this->db->query($query);
$query->bindParam(':id', $id , PDO::PARAM_INT);
$query->bindParam(':name', $name);
$query->bindParam(':ic', $ic);
$query->bindParam(':qualification', $qualification);
$result = $query->execute();
return $result;
}
// CMP999Controller.php
public function add($data) {
if ( $this->model('CMP999')->addData($_POST) > 0) {
header('Location: ' .BASE_URL . '/Compliance/CMP999');
return $data;
exit;
}
}
插入后我希望所有数据都显示在表中...