php - All data is become NULL when run Update Query MySQL -


i have problem mysql query update , think it's weird. run update query in code where clause in query. but, when stop query data in table become null , not in data contain in where clause in table.

this code :

$book = json_decode($this->input->post('stringify'));  foreach ($book $row) {     $data = array(               'price' => $row->price,               'date_modified' => date("y-m-d h:i:s"),               'modified_by' => $row->username            );      $this->db->where('id', $row->id);     $this->db->where('book_id', $row->book_id);     $this->db->update('book_availability', $data); } 

i create query codeigniter framework. want know why query update data in table , not data in where clause. maybe server cause problem or possible cause that. hope suggest me why happen. thanks.

it can happen if there no value associated variables using condition

it validate data before inserting database:

foreach ($book $row) {   if(isset($row->id) && $row->id != '' && isset($row->book_id) && $row->book_id != '' ) {     $data = array(               'price' => $row->price,               'date_modified' => date("y-m-d h:i:s"),               'modified_by' => $row->username            );      $this->db->where('id', $row->id);     $this->db->where('book_id', $row->book_id);     $this->db->update('book_availability', $data);    } } 

now db data updated if have values given variables. can use more validation checking id if numeric (as per db structure ) or invalid.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -