$value) { if ($key== "id") continue; //if ($key=="occupation") { $value = json_encode(explode(' ', rtrim($value))); } $fieldstring .= '"' . $key .'"'.':'.'"'.$value.'"'.','; } $fieldstring=substr($fieldstring,0,-1); $putfields = '{"document" : { "$set" : {'. $fieldstring .'} } }'; // send request to the service using curl - http://us2.php.net/curl $ch = curl_init(); // initialize curl handle curl_setopt($ch, CURLOPT_URL, $request); // set url to post to - must match above curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); // HTTP method curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $putfields); // HTTP entity-body curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( // set HTTP header fields 'Content-Type: application/json', 'Content-Length: ' . strlen($putfields)) // can change to $putfields ); if(curl_exec($ch) === false) // run the whole process with error handling and creates the return link { echo 'Curl error: ' . curl_error($ch) . '
'; } else { echo 'Operation completed without any errors. Return to home.'; } curl_close($ch); // close connection ?>