CodeIgniter Forums
Codeigniter Query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Codeigniter Query (/showthread.php?tid=73277)



Codeigniter Query - amansusanto - 04-06-2019

i have problem to saving data

this is my Model
i use Sql Server Database

  function UpdateEdit($data)
  {

     $this->db->trans_start();
     $sql = " update [do] set customer='" . $data['Customer'] . "', tgl='" . $data['Tgl'] . "', Notes='" . $data['Notes'] . "', Total=" . $data['Total']
          . " where doid='" . $data['Doid'] . "'";    
     print_r($sql);

      $head =  $this->db->query($sql);

     $this->db->delete("from DoDtl where Doid='" . $Doid . "'");

     $this->db->query($data['Detail']);
     $this->db->trans_complete();

     return TRUE;
  }



RE: Codeigniter Query - php_rocs - 04-06-2019

@amansusanto,

What errors are you seeing? Also, I wouldn't do you query like that.  You could open yourself up to sql injections.  I would use this the query binding method instead (https://www.codeigniter.com/userguide3/database/queries.html#query-bindings ).

PHP Code:
      $sql " update [do] set customer=?, tgl=?, Notes=?, Total=? where doid=?"  

      $head 
 $this->db->query($sql,[$data['Customer'],$data['Tgl'],$data['Notes'],$data['Total'],$data['Doid']]);
 
     print_r($this->db->last_query()); 



RE: Codeigniter Query - amansusanto - 04-07-2019

(04-06-2019, 12:23 PM)php_rocs Wrote: @amansusanto,

What errors are you seeing? Also, I wouldn't do you query like that.  You could open yourself up to sql injections.  I would use this the query binding method instead (https://www.codeigniter.com/userguide3/database/queries.html#query-bindings ).

PHP Code:
      $sql " update [do] set customer=?, tgl=?, Notes=?, Total=? where doid=?"  

      $head 
 $this->db->query($sql,[$data['Customer'],$data['Tgl'],$data['Notes'],$data['Total'],$data['Doid']]);
 
     print_r($this->db->last_query()); 

i have wrong type table column name. now already solved..
Thank you