【发布时间】:2019-04-03 18:49:02
【问题描述】:
我想删除表中的数据,但由于这个问题我无法删除数据。错误号:1064
这是我的控制器
class Dosen extends CI_Controller
{
public function __construct()
{
parent ::__construct();
$this->load->library('form_validation');
$this->load->model('Dosen_model');
}
public function index()
{
$data['judul'] = 'Daftar Dosen';
$data['dosen'] = $this->Dosen_model->getAllDosen();
$this->load->view('templates/header', $data);
$this->load->view('dosen/index', $data);
$this->load->view('templates/footer');
}
public function tambah()
{
$data['judul'] = 'Form tambah data Dosen';
$this->form_validation->set_rules('nip','NIP','required');
$this->form_validation->set_rules('nama','Nama','required');
if ($this->form_validation->run()==FALSE)
{
$this->load->view('templates/header', $data);
$this->load->view('dosen/tambah');
$this->load->view('templates/footer');
}
else
{
$this->Dosen_model->tambahDataDosen();
$this->session->set_flashdata('flash','Ditambahkan');
redirect('Dosen');
}
}
public function hapus($nip)
{
$this->Dosen_model->hapusDataDosen($nip);
$this->session->set_flashdata('flash','Dihapus');
redirect('Dosen');
}
这是我的模特
<?php
class Dosen_model extends CI_Model
{
public function getAllDosen()
{
$query = $this->db->get('daftar_dosen');
return $query->result_array();
}
public function tambahDataDosen()
{
$data = [
"nip" => $this->input->post('nip'),
"nama" => $this->input->post('nama'),
"prodi" => $this->input->post('prodi'),
];
$this->db->insert('daftar_dosen',$data);
}
public function hapusDataDosen($nip)
{
$this->db->where('nip',$nip);
$this->db->delete('daftar_dosen',$data);
}
}
输出是: 遇到 PHP 错误 严重性:通知
消息:未定义变量:数据
文件名:models/Dosen_model.php
行号:23
回溯:
文件:C:\xampp\htdocs\endtest\application\models\Dosen_model.php 线路:23 函数:_error_handler
文件:C:\xampp\htdocs\endtest\application\controllers\Dosen.php 线路:40 功能:hapusDataDosen
文件:C:\xampp\htdocs\endtest\index.php 线路:315 函数:require_once
然后
发生数据库错误 错误号:1064
您的 SQL 语法有错误;查看与您的 MariaDB 服务器版本相对应的手册,了解在第 3 行的“IS NULL”附近使用的正确语法
从daftar_dosen 删除,其中nip = '0001' 并且为空
文件名:C:/xampp/htdocs/endtest/system/database/DB_driver.php
行号:691
【问题讨论】:
标签: php mysql codeigniter mariadb codeigniter-3