aaronqli
aaronqli

Reputation: 809

PHP: POST JSON string - urlencode doesn't seem to work

When I try the following:

     $post_string='data='.urlencode(json_encode($data));  //data is a big nested array
     $post_string='&password='.urlencode($password);
     $post_string='&username='.urlencode($username);

The $_POST data I received on the other server becomes corrupted - either password or username is missing. I suspect I did not encode the data into JSON in the correct way. What have I done wrong?

Upvotes: 1

Views: 1506

Answers (1)

Quentin
Quentin

Reputation: 943556

You are using = to assign a new value. Each line discards the previous value. You want to use .= for a concatenating assignment.

Upvotes: 2

Related Questions