/    Sign up×
Community /Pin to ProfileBookmark

Checkbox Checked and Save Multiple Checkbox in database

Hi Sir,
I creating a form with checkbox
for example I checked the Add Employee and Upload Employee, after I click the Submit button
the output is 2 and 3 which is correct but only the Upload Employee was checked.
How can it be that the Add Employee and Upload Employee was checked.
Also how can save checkbox check in the database.

[CODE]
if(isset($_POST[‘submit’]))
{
if(!empty($_POST[‘access’])) {
$access = $_POST[‘access’];
echo “You chose the following color(s): <br>”;
foreach ($access as $access_id){
echo $access_id.”<br />”;
}} // end brace for if(isset

else {

echo “You did not choose a color.”;

}
}

<input type=”checkbox” name=”access[]” id=”access” value=”1″ <?php if($access_id==1) echo ‘checked=”checked”‘; ?>>Search/View Employee Information<br>
<input type=”checkbox” name=”access[]” id=”access” value=”2″ <?php if($access_id==2) echo ‘checked=”checked”‘; ?>>Add Employee<br>
<input type=”checkbox” name=”access[]” id=”access” value=”3″ <?php if($access_id==3) echo ‘checked=”checked”‘; ?>>Upload Employee<br>
<input type=”checkbox” name=”access[]” id=”access” value=”4″ <?php if($access_id==4) echo ‘checked=”checked”‘; ?>>Permission<br>
<input type=”checkbox” name=”access[]” id=”access” value=”5″ <?php if($access_id==5) echo ‘checked=”checked”‘; ?>>Vacation<br>
<input type=”checkbox” name=”access[]” id=”access” value=”6″ <?php if($access_id==6) echo ‘checked=”checked”‘; ?>>Calendar Event<br>

<input type=”submit” name=”submit” id=”submit” value=”Submit”>
[/CODE]

Thank you

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmSep 09.2015 — Your posted code is either confusing or incomplete. Where is the beginning of your form? Where is the end? Where is $access_id defined and set when the form elements (checkboxes) are being output?
×

Success!

Help @newphpcoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...