6

I'm receiving the following error Warning: array_merge(): Argument #1 is not an array when processing $_POST['cpl'], although $_POST['add'] works fine

if (is_array($_POST['add'])) {
    foreach ($_POST['add'] as $key => $value) $_POST['add'][$key] = mysql_real_escape_string($value);
    $en = array_merge($en, $_POST['add']);
}

if (is_array($_POST['cpl'])) {
    foreach ($_POST['cpl'] as $key => $value) $_POST['cpl'][$key] = mysql_real_escape_string($value);
    $cp = '';
    $cp = array_merge($cp, $_POST['cpl']);
}

2 Answers 2

10

That's because $cp is a string (you explicitly defined it that way).

$cp = ''; // <-- empty string
$cp = array_merge($cp, $_POST['cpl']);

should be:

$cp = array(); // <--now it's an array
$cp = array_merge($cp, $_POST['cpl']);
Sign up to request clarification or add additional context in comments.

Comments

4

You have these lines:

$cp = '';
$cp = array_merge($cp, $_POST['cpl']);

It's self-explanatory: $cp is a string first, the error is simply about this fact. Initialize it with array() instead.

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.