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

PHP Code:
$this->db->trans_start();
{
    $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 
1;
    
    if 
($row)
    {
        $id $row['max_val'] + 1;
    }
    
    $c
['id'] = $id;
    
    $this
->db->set('t''NOW()'FALSE);
    $this->db->insert('c'$c);
}
$this->db->trans_complete();

return 
$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).
Thanks!
Reply
#2

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'); 
Reply
#3

@geekita,
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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB