php - how to update table using api in codeigniter -



php - how to update table using api in codeigniter -

i'm stuck @ updating table row using api in codeigniter, have read tutorial code tutsplus

but there's no spesific it, tried myself , got stuck :-(

url request:

http://localhost/work/bnilife/v1/signup/user/post?nopol=a1b2c3d4e5&username=agus&password=kucingtikus&captcha=c12ds

here's json respon:

{ "error": "error :-( " }

my controller below:

public function user_post() { date_default_timezone_set('asia/jakarta'); $datestring ="%y-%m-%d %h:%i:%s"; $time =time(); $datetime =mdate($datestring, $time); $data = array ( 'nopol' => $this->input->get_post('nopol'), 'username' => $this->input->get_post('username'), 'password' => sha1($this->input->get_post('password')), 'created_at' => $datetime, 'updated_at' => $datetime ); $result = $this->signup_m->signup_insert($data); if($result) { $this->response($data, 200); } else { $this->response(array('error' => 'error :-( '),400); } }

my model:

public function signup_insert($data) { // query check whether username exist or not $condition = "nopol=" . "'" . $data['nopol'] . "'" ; $this->db->where($condition); $this->db->update('user', $data); }

is there wrong or misstype, give thanks guys i'm new @ stuff.

you can check codeigniter documentation how working database methods http://www.codeigniter.com/userguide3/database

public function signup_insert($data) { $this->db->where('nopol',$data['nopol']); homecoming $this->db->update('user', $data); }

in case need , homecoming else can't utilize method $result equal null..

check , ci form validation library don't validate input info (even escaped) may generate problems. and importantly, should write proper method names: signup_insert should insert not update.

php codeigniter api insert-update

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -