How to Declare checkbox variable in php

Html checkbox input type not accept normal php variable declaration method, its can use for another way.


Html Code:

<h2>Color Type:</h2>
<input type="checkbox" name="color[]" value="Red" ><span style="font-size:20px;">Red</span><br>
<input type="checkbox" name="color[]" value="Blue" ><span style="font-size:20px;">Blue</span><br>
<input type="checkbox" name="color[]" value="Green" ><span style="font-size:20px;">Green </span><br>
<input type="checkbox" name="color[]" value="Black" ><span style="font-size:20px;">Black</span>

use name like that method ( name=”color[]”).

php  checkbox variable declaration way for:


$color = isset($_POST['color']) ? $_POST['color'] : '';
$check_color  = is_array($color) ? implode(", ", $color) : '';

$query=mysqli_query($con,"insert into job(color)values ('".$check_color."'));


php checkbox variable declaration use for implode and array  because its muti-level system.

We hope, you all are like this topic.if you have any query,please drop me your comment below comment box section,we are reply to you as soon as possible.

Add a Comment

Your email address will not be published. Required fields are marked *