-
Tomasiomat
Newbie
-
Posts: 7
Threads: 3
Joined: Feb 2024
Reputation:
1
I want to do a DB update, but I always get the error message mentioned above: There is no data to update.
My model:
PHP Code: <?php
namespace App\Models;
use CodeIgniter\Model;
class EinheitenModel extends Model { // Table protected $table = 'einheiten'; protected $primaryKey = 'einh_id'; // allowed fields to manage protected $allowedFields = ['einh_art_id, einh_etg, einh_lage, einh_qm, einh_zimmer, einh_kueche, einh_bad, einh_ebk, einh_dusche, einh_badewanne, einh_balkon, einh_terasse, einh_beschr'];
My Controller:
PHP Code: $this->data['request'] = $this->request; $post = [ 'einh_art_id' => $this->request->getPost('einh_art_id'), 'einh_etg' => $this->request->getPost('einh_etg'), 'einh_lage' => $this->request->getPost('einh_lage'), 'einh_qm' => $this->request->getPost('einh_qm'), 'einh_zimmer' => $this->request->getPost('einh_zimmer'), 'einh_kueche' => $this->request->getPost('einh_kueche'), 'einh_bad' => $this->request->getPost('einh_bad'), 'einh_ebk' => $this->request->getPost('einh_ebk'), 'einh_badewanne' => $this->request->getPost('einh_badewanne'), 'einh_dusche' => $this->request->getPost('einh_dusche'), 'einh_balkon' => $this->request->getPost('einh_balkon') ]; if(!empty($this->request->getPost('einh_id'))) $save = $this->EinheitenModel->where(['einh_id'=>$this->request->getPost('einh_id')])->set($post)->update();
Request Variable Post in the error message:
PHP Code: $_POST Key Value einh_id 1 einh_etg einh_art_id 6 einh_lage rechts einh_qm 70 einh_zimmer 3 einh_kueche 1 einh_bad 1 einh_ebk 1 einh_badewanne 1 einh_dusche 1 einh_balkon 1
As you can see, all variables are transferred via post, all fields are set in the model under Allowed Fields and a primary key is also transferred.
PHP Code: Can someone give me a hint where else I should look?
Cheers, Thomas
-
kenjis
Administrator
-
Posts: 3,655
Threads: 97
Joined: Oct 2014
Reputation:
226
-
Tomasiomat
Newbie
-
Posts: 7
Threads: 3
Joined: Feb 2024
Reputation:
1
03-01-2024, 06:45 AM
(This post was last modified: 03-01-2024, 06:47 AM by Tomasiomat.)
The error still occurs
PHP Code: $this->data['request'] = $this->request; $data = [ 'einh_art_id' => $this->request->getPost('einh_art_id'), 'einh_qm' => $this->request->getPost('einh_qm'), 'einh_zimmer' => $this->request->getPost('einh_zimmer'), 'einh_kueche' => $this->request->getPost('einh_kueche'), 'einh_bad' => $this->request->getPost('einh_bad'), 'einh_ebk' => $this->request->getPost('einh_ebk'), 'einh_badewanne' => $this->request->getPost('einh_badewanne'), 'einh_dusche' => $this->request->getPost('einh_dusche'), 'einh_balkon' => $this->request->getPost('einh_balkon') ]; if(!empty($this->request->getPost('einh_id'))) { $einh_id = $this->request->getPost('einh_id'); $this->EinheitenModel->update($einh_id, $data); }
-
kenjis
Administrator
-
Posts: 3,655
Threads: 97
Joined: Oct 2014
Reputation:
226
03-01-2024, 03:24 PM
(This post was last modified: 03-01-2024, 03:25 PM by kenjis.)
This code is wrong. The element is a string. You must set all fields as array elements.
PHP Code: protected $allowedFields = ['einh_art_id, einh_etg, einh_lage, einh_qm, einh_zimmer, einh_kueche, einh_bad, einh_ebk, einh_dusche, einh_badewanne, einh_balkon, einh_terasse, einh_beschr'];
-
Tomasiomat
Newbie
-
Posts: 7
Threads: 3
Joined: Feb 2024
Reputation:
1
Oh my god, at first I thought it was a bug in CI, but the bug is probably in my head :-)
Thanks for the correct hint.
|