0

I successfully passed following values with AJAX post method to my PHP file

name:John
email:[email protected]
comments:Hello
category_list[]:Books
category_list[]:Documents

The problem is that the following code sends HelloArray instead of HelloBooksDocuments. Could you please help me to find my mistake.

$email = $_POST["email"];
$name = $_POST["name"]);    
$comments = $_POST["comments"];
$categories = $_POST["category_list"];  //the problem is here  
1

1 Answer 1

2

Replace this line:

$comments= $comments.$categories;

With:

$comments= $comments.implode("", $categories);

The reason is that that variable $categories is an array, and you need to convert it to a string.

This you can do with implode. If you want them separated by a comma, then pass that as the first argument, replacing the empty string "" I have suggested above.

Of course, you can change this, and use another separator of your choice.

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

1 Comment

using his expected output, maybe change the delimiter to "" ?

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.