PHP REST API - PUT Displaying 404 -
i trying make simple web service, updates field when page hit. have tried code purposes of stack overflow. when try go page it's bringing 404.
firstly here web service code (i'm using slim) (i've missed out database connection stuff):
$app->put('/offer/:id', 'updateoffer'); function updateoffer($id) { global $app; $req = $app->request(); $increment = $req->params('increment'); $sql = "update offers set claims=:increment id=:id"; try { $dbcon = getconnection(); $stmt = $dbcon->prepare($sql); $stmt->bindparam("increment", $increment); $stmt->bindparam("id", $id); $status->status = $stmt->execute(); $dbcon = null; echo json_encode($status); } catch(pdoexception $e) { echo '{"error":{"text":'. $e->getmessage() .'}}'; } } and on page want visit code follows:
$url = 'http://localhost/api/offer/'.$id1; $fields = array( 'id' => urlencode($id), 'increment' => urlencode($increment) ); //url-ify data post foreach($fields $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string, '&'); //open connection $ch = curl_init(); //set url, number of post vars, post data curl_setopt($ch,curlopt_url, $url); curl_setopt($ch,curlopt_post, count($fields)); curl_setopt($ch,curlopt_postfields, $fields_string); //execute post $result = curl_exec($ch); //close connection curl_close($ch); i can't head around going wrong. can work form (so know web service works)
Comments
Post a Comment