0

I used a POST method later I want to add POST request to a variable but I get an error. Why I get object error?

Error code

PHP Catchable fatal error: Object of class stdClass could not be converted to string

POST data

array(16) { ["lat"]=> string(15) "41.008550564147" ["lng"]=> string(15) "28.978239484058" ["time"]=> string(1) "6" ["type"]=> string(6) "status" ["status"]=> string(0) "" ["category"]=> string(0) "" ["subCategory"]=> string(0) "" ["room"]=> string(0) "" ["buildingAge"]=> string(0) "" ["sfloor"]=> string(0) "" ["floor"]=> string(0) "" ["square"]=> string(0) "" ["price"]=> string(0) "" ["currency"]=> string(0) "" ["value"]=> string(0) "" ["feedback"]=> string(0) "" }

PHP code

    foreach ($_POST as $key => $value) {
        $params .= $key . "=" . $value . "&";
    }
    echo $params;
3
  • 2
    Are you trying to do this? php.net/manual/en/function.http-build-query.php Commented Nov 14, 2017 at 14:26
  • 1
    isn't $params previously defined as CLASS? Try add $params = ""; before foreach Commented Nov 14, 2017 at 14:27
  • Thanks http_build_query worked.. Commented Nov 14, 2017 at 14:28

1 Answer 1

1

Use http_build_query instead.

echo http_build_query($_POST);
Sign up to request clarification or add additional context in comments.

Comments

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.