CodeIgniter Forums
trans_status wrong value - Printable Version

+- CodeIgniter Forums (
+-- Forum: Using CodeIgniter (
+--- Forum: General Help (
+--- Thread: trans_status wrong value (/showthread.php?tid=71901)

trans_status wrong value - geekita - 10-06-2018

PHP Code:
    $query_str "SELECT MAX(id) max_val FROM c WHERE i = ? ";

    $query $this->db->query($query_str, array($c['i']));
    $row $query->row_array();
        $id $row['max_val'] + 1;
['id'] = $id;

$this->db->trans_status() === FALSE FALSE $c['id']; 
Hi! I'm using the above code to read the max id from a table and then add a new row with maxid + 1. I call this piece of code via an ajax call and it works the very first time. If I call it a second time, trans_status equals FALSE. This is so weird because if I refresh the whole page via F5 it works every time. What am I missing? Huh  I'm using CI 3.1.9 + Mysql InnoDB 5.6.20 (mysqli driver).

RE: trans_status wrong value - geekita - 10-07-2018

The problem pops out when stricton => TRUE. I was trying to insert an empty string into an int column. What is still obscure to me is the first time I load the page and submit data via ajax, $data['x'] equals NULL. If I re-submit same data without refreshing page, $data['x'] equals "" (empty string).

This is how I get data from post

PHP Code:
$data['x'] = $this->input->post('x'); 

RE: trans_status wrong value - php_rocs - 10-08-2018

Why are you doing this? All you have to do is configure your database table correctly and it will automatically do this for you. You are adding an extra layer of code where you do not need to.