close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

MYSQLi Multiple Checkbox Insert

Thread began 2/28/2018 7:56 am by georgina_barrett_187762 | Last modified 2/28/2018 12:23 pm by georgina_barrett_187762 | 1220 views | 1 replies


MYSQLi Multiple Checkbox Insert

I have a list of checkboxes (created via a repeat region from a MYSQLi recordset). I want the user to be able to select 1 or more of the checkboxes and then that get inserted in the database.

I have this working correctly using text boxes, however when I have used exactly the same code but with checkboxes it doesn't work. It does insert into the database however the value is blank. The HotelID value gets inserted because that is the same for all the checkboxes - but the AName value doesn't.

Strangely if I check the first checkbox in the repeat region - that value does get stored but for all of the other check boxes the value that is entered into the database is NULL. If I select other check boxes without selecting the first one in the list - they get inserted but all of them have a NULL value.

This is my code

for ($x=0; $x<sizeof($_POST['AName']); $x++) {
if ((isset($_POST["Submit"]) || isset($_POST["Submit_x"]))) {
$InsertQuery = new WA_MySQLi_Query($connect_i);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "amenities";
$InsertQuery->bindColumn("ResortID", "i", "".(((isset($_POST["HotelID"]))?$_POST["HotelID"]:"")) ."", "WA_DEFAULT");
$InsertQuery->bindColumn("Text", "s", "".($_POST['AName'][$x]) ."", "WA_DEFAULT");
$InsertGoTo = "index.php";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";

<form action="" method="post" enctype="multipart/form-data" name="form1">
<div class="row">
<?php $i = 1; ?>
while(!$Recordset1->atEnd()) {
<div class="col-12 col-md-6">
<input name="AName[<?php echo $i; ?>]" type="checkbox" id="AName" value="<?php echo($Recordset1->getColumnVal("AName")); ?>"> <label><?php echo($Recordset1->getColumnVal("AName")); ?> </label>
</div><?php ($i++); ?>
$Recordset1->moveFirst(); //return RS to first record
<input name="Submit" type="submit" id="Submit" value="Submit">
<input name="HotelID" type="hidden" id="HotelID" value="<?php echo($_GET["HotelID"]) ?>">

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question





Ease of use


security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...