I'm trying to implode some checkbox values into a single String to store it on a Database field (as it is the only way I think I can do it), but I'm getting this error:
implode(): Invalid arguments passed
My HTML code is:
<input type="checkbox" name="oportunitats[]" value="1">
<input type="checkbox" name="oportunitats[]" value="2">
<input type="checkbox" name="oportunitats[]" value="3">
<input type="checkbox" name="oportunitats[]" value="4">
And my PHP looks like this:
$chk_oportunitats = implode(",",$_POST["oportunitats"]);
How can I fix this error?
The problem was I was checking $chk_oportunitats before any checkbox was selected, so the array was empty.
Solution PHP looks like this:
if (isset($_POST["oportunitats"])){
$chk_oportunitats = implode(",",$_POST["oportunitats"]);
}