Welcome Guest, Not a member yet? Register   Sign In
The query does not save data to db
#1

[eluser]Giga[/eluser]
Hi friends,
I just started using code igniter and unfortunately in front of a strange problem!

I use xampp 1.7.3 with the latest version of CI.

I have created a model:
Code:
class User_model extends Model{
        function AddUser($options=array())
    {
          $utente = array('username'=>$options['username'],
                    'pass'=>$options['pass'],
              'tipo'=>$options['tipo'],
              'p_iva_pv'=>$options['p_iva_pv']);

          $this->db->insert_string('utente',$utente);
          return $this->db->insert_id();
        }
}
So i have created Controller:
Code:
class Blog extends Controller {

    
    function prova()
    {
    
    $user=array('username'=>'giuseppe','pass'=>'prova','tipo'=>4,'p_iva_pv'=>'01234');
        
        $this->load->model('user_model');    
        $a = $this->user_model->addUser($user);
    echo $a;
    }
}
Now calling .../index.php/Blog/prova/ return on desktop value 0(zero)
If control phpmyadmin not added any lines

Why return zero(0) and not added the line on db?
#2

[eluser]rogierb[/eluser]
well, it is not supposed to insert. $this->db->insert_string() returns a... string! ;-)

I know... Easy to get confused but all you did was generate a insert string.
If you want to execute that string, you need $this->db->query($str) or use $this->db->insert()

The latter does an insert. I guesst that is the one you want.
#3

[eluser]Giga[/eluser]
ops... thank you




Theme © iAndrew 2016 - Forum software by © MyBB