0

Maybe this is an easy question.

I have a variable which save the user id in it.

$user_id = $_REQUEST['user_id'];

and then I have the URL like this :

try 
{
    $response = $client->delete('admin/user/**USER ID SHOULD HERE**',[
    'headers' => ['Authorization' => $_SESSION['login']['apiKey']]
    ]);
}

I already try to put variable $user_id like this admin/user/$user_id in that URL but nothing happens.'

This is the delete method()

    public function delete($url = null, array $options = [])
    {
        return $this->send($this->createRequest('DELETE', $url, $options));
    }

Am I wrote something wrong ? Thanks :)

6
  • What does nothing happens mean? The url did not have the user id number? Commented Nov 18, 2014 at 16:59
  • The url containing the value of user id, but the error message I made said "failed to delete" Commented Nov 18, 2014 at 17:08
  • You probably need to show the code for the $client object's delete() method to figure out the error. Commented Nov 18, 2014 at 17:10
  • You should do some exception handling in a catch Commented Nov 18, 2014 at 17:16
  • $response = $client->delete('admin/user/' . $user_id, [... Commented Nov 18, 2014 at 17:17

1 Answer 1

1

PHP variables will not be parsed inside of a single quoted string. You should use "admin/user/$user_id" if you want the variable's value to be used.

So you could write it like this:

$response = $client->delete("admin/user/$user_id",[

Or simply by concatenating the string and user id variable using .:

$response = $client->delete('admin/user/'.$user_id,[
Sign up to request clarification or add additional context in comments.

2 Comments

I already tried sir, but the error message still said "failed to delete". I already try to print the value of $_REQUEST['user_id'] and the value is there.
well @Monk it looks like my answer is the same as what ended up working for you

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.