Welcome Guest, Not a member yet? Register   Sign In
trans_status wrong value

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).

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'); 

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.

Theme © iAndrew 2016 - Forum software by © MyBB