Reputation: 47
I am trying to update my API with an update curl function but am struggling to work out why it isn't working
The areas where it may be wrong is key($id)
I want it to
extract the ID column based on the key value for the ID array.
$URL
I want to create the URL based on the const variables plus the resource name plus the value of the ID array that has been passed through rawurlencode
.
So far this is my update code, but am wondering what area is wrong. I can provide more info if needed and appreciate any help, thanks
<?php
function update(array $id,array $vaules, $resourcename)
$jsonData = json_encode($vaules);
key($id);
$url = DOMAIN.FOLDER.APIPATH.$resourcename.rawurlencode("/".$id);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,array ('content-type: application/json'));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,PUT);
curl_setopt($ch,CURLOPT_POSTFIELDS,$jsonData);
curl_exec($ch);
curl_getinfo(CURLINFO_HTTP_CODE);
}
Upvotes: 1
Views: 47
Reputation: 25336
The function key()
returns the current key in an array (according to the internet pointer). Right now you're not doing anything with it, you're calling the function and not assigning it anywhere.
Did you mean to write: rawurlencode("/".key($id).$vaules);
?
As your code is right now, assuming $id
is an array, you're trying to convert an array into a string, which I doubt is what you want.
Upvotes: 2