对不起,我是 CI4 或 CI3 的新手,
我想用表格更新我的数据库。但它无法更新我想要的位置,即使我将代码放在其中,如果我删除 where 代码,他们将更新我数据库中的所有记录,请我一直在阅读 CI4 的文档,我仍然不明白为什么我的代码无法检测到 where 代码。
这是我的完整控制器代码
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class User extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('form_validation');
}
public function index()
{
$data['title'] = 'My Profile';
$data['user'] = $this->db->get_where(
'user',
['email' => $this->session->userdata('email')]
)->row_array();
$this->load->view('templates/header', $data);
$this->load->view('templates/sidebar');
$this->load->view('templates/topbar');
$this->load->view('user/index');
$this->load->view('templates/footer');
}
public function edit()
{
$data['title'] = 'Edit Profile';
$data['user'] = $this->db->get_where(
'user',
['email' => $this->session->userdata('email')]
)->row_array();
$this->form_validation->set_rules('name', 'Full Name', 'required|trim');
if ($this->form_validation->run() == false) {
$this->load->view('templates/header', $data);
$this->load->view('templates/sidebar');
$this->load->view('templates/topbar');
$this->load->view('user/edit');
$this->load->view('templates/footer');
} else {
//update data name / bio
$name = $this->input->post('name');
$email = $this->input->post('email');
$bio = $this->input->post('bio');
$data = array(
"name" => $name,
"bio" => $bio,
);
$this->db->where('email', $email);
$this->db->update('user', $data);
$this->session->set_flashdata('message', '<div class="alert alert-success" style="text-align:center;" role="alert">
Your profile has been updated!</div>');
redirect('user/edit');
}
}
}
而且我不使用任何模型:/