0

I'm getting an error that says

Warning: implode():Invalid arguments passed

I do not understand why it is so...

Here is my code.

if(isset($_POST['consultationbutton'])){        
    $image = addslashes(file_get_contents($_FILES['selectedfile']['tmp_name'])); //SQL Injection defence!
    $checkedcondition = implode(",",$_POST['skincondition']);
    $checkedproduct = implode(",",$_POST['skincareinuse']);
    $consultquery="INSERT INTO counsel(nric,dateconsulted,editableface,skincarecurrentlyinuse,skincondition) VALUES('132','$_POST[storedate]','{$image}','$checkedproduct','$checkedcondition')";
    mysqli_query($dbconn,$consultquery);
}   

$_POST['skincondition'] and $_POST['skincareinuse'] are the name of my checkboxes.

4
  • 4
    I gues that $_POST['skincondition'] or $_POST['skincareinuse'] are not arrays. Did you check their contents? Commented Jun 15, 2016 at 10:35
  • 1
    Implode works on array have you checked these are array. Try print_r($_POST['skincondition']); just to check Commented Jun 15, 2016 at 10:36
  • @marcus, I guess you need to use explode here if you need to convert them to string or make the checkbox field name as skincareinuse[] Commented Jun 15, 2016 at 11:00
  • Yes i didnt set it as arrays in my html, my bad, but thanks guys :) And the implode works fine now, thanks for the input. Commented Jun 15, 2016 at 11:07

1 Answer 1

2

HTML Part

<form action="" method="post">
<input type="checkbox" name="skincondition[]" value="skincondition_1" />skincondition_1

<input type="checkbox" name="skincondition[]" value="skincondition_2" />skincondition_2

<input type="checkbox" name="skincondition[]" value="skincondition_3" />skincondition_3

<input type="checkbox" name="skincondition[]" value="skincondition_4" />skincondition_4

<input type="checkbox" name="skincondition[]" value="skincondition_5" />skincondition_5

<input type="submit" name="consultationbutton">
</form>

PHP code

if(isset($_POST['consultationbutton'])){        
$checkedcondition = implode(",",$_POST['skincondition']);
echo $checkedcondition;
}

working fine for me, please do share your HTML code so that i can tell you better.

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

1 Comment

It worked great now! I placed the name as name="skincondition" forgot to make it into an array, thanks for the help :)

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.