1

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);
}
1
  • What do you get in getinfo? Commented Dec 10, 2015 at 17:39

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

10 Comments

Thanks for your reply with key i want it to extract the id coloum based on the key vaule, okay so maybe i need to assign it within the url. Also nope i think this is pasrt of the issues i have updated it without vaules.
You need to fix rawurlencode(), $id is an array, not a string. Can you show a var_dump() of what $id is?
Hi $id the primary key, eg: id=Barth%2C+John&idColumn=Author_Name i am unsure on how var_dump works
I'm not sure what you mean. The function definition shows it's an array, update(array $id ...), it's not a string.
Hi sorry yep id is an array
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.