• 13

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

store checkbox value to mysql database

I have problem in storing checkbox values in mysql db (only the last value is stored in the database). How can I fix this code to store all checked values?

<label class="q" for="q1">Which, if any, of these activities did you do on the Internet in the last 30 days? 
<input name="q1[]" type="checkbox" value="a1">Used e-mail<br>
<input name="q1[]" type="checkbox" value="a2">Used instant messenger & chat room<br>
<input name="q1[]" type="checkbox" value="a3">Made a purchase for personal use<br>
<input name="q1[]" type="checkbox" value="a4">Downloaded/Played a video game<br>
<input name="q1[]" type="checkbox" value="a5">Obtained news/information/current events<br>
<input name="q1[]" type="checkbox" value="a6">Looked for employment (Used classified listings)<br>
<input name="q1[]" type="checkbox" value="a7">Looked for recipes<br>
<input name="q1[]" type="checkbox" value="a8">Downloaded a movie<br>



$sql="INSERT INTO $tbl_name(q1)VALUES('$q1')";
        <form action="" method="post">
            <table width="50%">
        <td><input type="checkbox"name="boxes[]"value="8am">1</input></td>
        <td><input type="checkbox"name="boxes[]"value="10am">3</input></td>
            <input type="submit" name="submit">
            $t1=implode(',', $_POST['boxes']);
            $s = "insert into new(time) values('$t1')"; 
                    echo "insert success";
                    echo "error in inserting";



please try this.

  • 3
Reply Report

but I think create a new table for those Items refer to main id. then you can dynamically handle this: I need a checkbox about payment options like:

<div class="form-group row">
                                <label for="default-input" class="col-md-2 control-label">Payment Options</label>
                                <div class="col-md-10">
                                    <input name="pamentoptionsValue[]" id="checkbox-0" value="1" class="" type="checkbox">
                                    <label for="checkbox-0" class="control-label"> Cash </label>
                                    <input name="pamentoptionsValue[]" id="checkbox-1" value="2" class="" type="checkbox">
                                    <label for="checkbox-1" class="control-label"> Visa </label>
                                    <input name="pamentoptionsValue[]" id="checkbox-1" value="3" class="" type="checkbox">
                                    <label for="checkbox-1" class="control-label"> MasterCard </label>
                                    <input name="pamentoptionsValue[]" id="checkbox-1" value="4" class="" type="checkbox">
                                    <label for="checkbox-1" class="control-label"> American  </label>
                                    <input name="pamentoptionsValue[]" id="checkbox-1" value="5" class="" type="checkbox">
                                    <label for="checkbox-1" class="control-label"> Express</label>
                                    <input name="pamentoptionsValue[]" id="checkbox-1" value="6" class="" type="checkbox">
                                    <label for="checkbox-1" class="control-label"> Nexus</label>
  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions