申し訳ありませんが、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');
}
}
}
そして、私はモデルを使用していません:/