使用API更新表我卡在使用API CI中, 我已经阅读code tutsplus如何在笨
教程,但没有spesific做更新表行, 所以我想我自己并卡住了:-(
网址:
http://localhost/work/bnilife/v1/signup/user/post?nopol=a1b2c3d4e5&username=agus&password=kucingtikus&captcha=c12ds
这里的JSON respon:
{
"error": "error :-("
}
我的控制器看起来像下面这样:
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);
}
}
我的模型:
public function signup_insert($data) {
// Query to check whether username already exist or not
$condition = "nopol=" . "'" . $data['nopol'] . "'" ;
$this->db->where($condition);
$this->db->update('user', $data); }
有没有什么不对或misstype, 感谢你们 我是新的这个东西。
1)。你真正想要做什么2)你已经在你的模型中编写了'//查询来检查用户名是否已经存在',而不是检查你是直接更新你的字段3)'if($ result)'它没有有任何意义 – 2015-04-06 11:19:51