php - Status 200 = HttpPut works? -
i'm trying modify value of database (mysql
). issue i'm using httput
on android
application , slim framework
micro framework of php xampp
managing database.
the problem it's doesn't modify database gives me status 200 when use response.getstatusline().getstatuscode()
.
and if didn't understood it, when receive status 200 it's because request had been succesful. can see here: status 200 ok
the request has succeeded.
am missing something? did understand wrong? why database doesn't change?
p.s. if need provide code, let me know in comment.
edit: here it's put
method in php script
.
$app->put("/cars/",function() use($app) { $name = $app->request->put("name"); $description = $app->request->put("description"); $idcar = $app->request->put("idcar"); try{ $connection = getconnection(); $dbh = $connection->prepare("update cars set name = ?, description = ? idcar = ?"); $dbh->bindparam(1,$name); $dbh->bindparam(2,$description); $dbh->bindparam(3,$idcar); $dbh->execute(); $connection = null; header("http/1.1 200"); header("content-type:application/json; charset=utf-8"); echo json_encode(array('status' => true),json_unescaped_unicode ); }catch(pdoexception $e) { echo "error: " . $e->getmessage(); } });
edit 2: here it's code in use httpput
.
class editcar extends asynctask<void, integer, void> { private car editcar; editcar(car editcar) { this.editcar = editcar; } protected void onpreexecute() { } protected void doinbackground(void... params) { try { string url = "http://ip of computer/project/cars/"; httpclient httpclient = new defaulthttpclient(); httpput method = new httpput(url); list<namevaluepair> namevaluepairlist = new arraylist<namevaluepair>(); namevaluepairlist.add(new basicnamevaluepair("name", editcar.getname())); namevaluepairlist.add(new basicnamevaluepair("description", editcar.getdescription())); namevaluepairlist.add(new basicnamevaluepair("idcar", integer.tostring(editcar.getidcar()))); method.setentity(new urlencodedformentity(namevaluepairlist)); httpresponse response = httpclient.execute(method); } catch (exception ex) { log.e("error", ex.tostring()); } return null; } protected void onprogressupdate() { } protected void onpostexecute() { } }
the 200 status says nothing update.
- do choose right database connection?
- your query looks normal, can't see parameter values. sure contains right values?
- you can specify data type bindparam method
- you 'update', lastinsertid 'insert'
but, can this:
print_r([$name,$description,$idcar]); // temporaly line debugging! $dbh = $connection->prepare("update cars set name = ?, description = ? idcar = ?"); $dbh->execute([$name,$description,$idcar]);
if use < php 5.4: [] must array()
Comments
Post a Comment