I was working on a personal project where I have an image grid with checkboxes, and wanted to insert in my database the values of the checkboxes, but can't figure out how to. I had success into inserting one of the values in my database, but when it gets to two or more, it only shows the first one.
My checkbox grid:
/* Responsive layout - makes a two column-layout instead of four columns */
@media (max-width: 800px) {
.row {
grid-template-columns: 1fr 1fr;
grid-gap: 1%;
align-items: start;
}
}
.gridlabel {
font-size: 10px;
margin-top: 70px;
color: #FFFFFF;
position: absolute;
font-weight: 900;
}
.gridlabelg {
text-align: center;
margin-left: 12px;
font-size: 10px;
margin-top: 60px;
color: #FFFFFF;
position: absolute;
}
ul {
list-style-type: none;
grid-template-columns: 1fr 1fr 1fr 1fr;
}
li {
display: inline-grid;
}
input[type="checkbox"][id^="cb"] {
display: none;
}
.lblimgs {
border: 1px solid #fff;
padding: 0px;
display: grid;
position: relative;
margin: 2px;
cursor: pointer;
}
.lblimgs:before {
background-color: white;
color: white;
content: " ";
display: block;
border-radius: 30%;
border: 1px solid grey;
position: absolute;
top: -5px;
left: -5px;
width: 25px;
height: 25px;
text-align: center;
line-height: 28px;
transition-duration: 0.4s;
transform: scale(0);
}
.lblimgs img {
height: 100px;
width: 144px;
transition-duration: 0.2s;
transform-origin: 50% 50%;
border-radius: 10px;
}
:checked+.lblimgs {
border-color: #ddd;
}
:checked+.lblimgs:before {
content: "✓";
background-color: rgb(173, 168, 168);
transform: scale(1);
}
:checked+.lblimgs img {
transform: scale(0.9);
/* box-shadow: 0 0 5px #333; */
z-index: -1;
}
<div class="images">
<ul>
<li><input type="checkbox" id="cb1" name="hotel" value="casamontanha" />
<label for="cb1" class="lblimgs"><img src="pictures/casamontanha.jpg" /></label>
</li>
<li><input type="checkbox" id="cb2" name="hotel" value="fillitheyo" />
<label for="cb2" class="lblimgs"><img src="pictures/filitheyo.jpg" /></label>
</li>
<li><input type="checkbox" id="cb3" name="hotel" value="hardrock" />
<label for="cb3" class="lblimgs"><img src="pictures/hardrock.jpg" /></label>
</li>
<li><input type="checkbox" id="cb4" name="hotel" value="rioquente" />
<label for="cb4" class="lblimgs"><img src="pictures/rioquente.jpg" /></label>
</li>
<li><input type="checkbox" id="cb5" name="hotel" value="sheraton" />
<label for="cb5" class="lblimgs"><img src="pictures/sheraton.jpg" /></label>
</li>
<li><input type="checkbox" id="cb6" name="hotel" value="apart" />
<label for="cb6" class="lblimgs"><img src="pictures/apart.jpg" /></label>
</li>
<li><input type="checkbox" id="cb7" name="hotel" value="lecanton" />
<label for="cb7" class="lblimgs"><img src="pictures/lecanton.jpg" /></label>
</li>
<li><input type="checkbox" id="cb8" name="hotel" value="pestana" />
<label for="cb8" class="lblimgs"><img src="pictures/pestana.jpg" /></label>
</li>
<li><input type="checkbox" id="cb9" name="hotel" value="catello" />
<label for="cb9" class="lblimgs"><img src="pictures/catello.jpg" /></label>
</li>
<li><input type="checkbox" id="cb10" name="hotel" value="wishnatal" />
<label for="cb10" class="lblimgs"><img src="pictures/wishnatal.jpg" /></label>
</li>
<li><input type="checkbox" id="cb11" name="hotel" value="malta" />
<label for="cb11" class="lblimgs"><img src="pictures/malta.jpg" /></label>
</li>
<li><input type="checkbox" id="cb12" name="hotel" value="lhc" />
<label for="cb12" class="lblimgs"><img src="pictures/lhc.jpg" /></label>
</li>
</ul>
</div>
I was trying to do something like:
$cb1=$_POST['hotel'];
$cbx1="";
foreach($checkbox1 as $cbx1)
{
$cb1 .= $cbx1.",";
}
New to programming, please understand!