【发布时间】:2015-06-10 18:50:29
【问题描述】:
我一直在使用 codeigniter 中的 api 更新表格行, 我已经阅读了code tutsplus的教程
但是没有什么特别的方法, 所以我自己尝试并卡住了:-(
网址请求:
http://localhost/work/bnilife/v1/signup/user/post?nopol=a1b2c3d4e5&username=agus&password=kucingtikus&captcha=c12ds
这是 json 响应:
{
"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); }
是否有任何错误或错误输入, 谢谢你们 我是这方面的新手。
【问题讨论】:
-
1)。你真正想要做什么 2)你已经在你的模型中写了
// Query to check whether username already exist or not,而不是检查你直接更新你的字段 3)if($result)这没有任何意义
标签: php codeigniter api insert-update