How to insert data from multiple checkbox values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Darrel
Forum Commoner
Posts: 33
Joined: Fri Oct 10, 2014 2:30 am

How to insert data from multiple checkbox values

Post by Darrel »

how to insert data from multiple checkbox values into database?

Hi, all. Currently i am facing some problem with my coding. I am used this code to insert data from multiple checkbox values into database. but its still not happen anything. Sorry, i am new to php. Please can anyone help me on this? I would be more appreciate if i get to solve this problem. Thank you so much.

Code: Select all

<script type="text/javascript">
var currentEnabled = null;
function enableElement(elem) {
if (currentEnabled) {
currentEnabled.disabled = true;
}
elem.disabled = false;
currentEnabled = elem;
}
</script>
<body background="images/form.jpg" bgcolour="#CC66FF">
<?php 
error_reporting(0);
session_start();
include('includes/header.html');
include('dbcon.php');
// Get values from form
if(isset($_POST['submit'])) {
$fdate = date('Y-m-d');
$ref_no = $_POST['ref_no'];
$from = $_POST['from'];
$copy = $_POST['copy'];
$description = implode(',',$_POST['description']);
$buyer = $_POST['buyer'];
$ref = $_POST['ref'];
$potential_annual = $_POST['potential_annual'];
$target_price = $_POST['target_price'];
$market_app = $_POST['market_app'];
$instruct = implode(',', $_POST['instruct']);
$comp_colour = $_POST['comp_colour'];
$pattern = implode(',', $_POST['pattern']);
$sole_colour = $_POST['sole_colour'];
$calender_pattern = $_POST['calender_pattern'];
$heel_type = $_POST['heel_type'];
$heel_colour = implode(',', $_POST['heel_colour']);
$moul_sole = $_POST['moul_sole'];
$top_fox = $_POST['top_fox'];
$top_colour = implode(',', $_POST['top_colour']);
$bottom_fox = $_POST['bottom_fox'];
$bottom_colour = implode(',',$_POST['bottom_colour']);
$last_type = $_POST['last_type'];
$boots_height = $_POST['boots_height'];
$size = $_POST['size'];
$total_pairs = $_POST['total_pairs'];
$date_required = $_POST['date_required'];
$lin_material = $_POST['lin_material'];
$cuff_material = implode(',', $_POST['cuff_material']);
$lace_colour = implode(',',$_POST['lace_colour']);
$brand = $_POST['brand'];
$colour = $_POST['colour'];
$lacquer_finishing = implode(',', $_POST['lacquer_finishing']);
$safety = implode(',', $_POST['safety']);
$features = implode(',', $_POST['features']);
$attachment = $_POST['attachment'];
$remarks = $_POST['remarks'];
$department = $_POST['department'];
$pair = $_POST['pair'];
$request_by = $_POST['request_by'];
$approval_status = $_POST['approval_status'];
$query = "INSERT INTO requisition ( fdate, ref_no, from, copy, description, buyer, ref, potential_annual, target_price, market_app, instruct, comp_colour, pattern, sole_colour, calender_pattern, heel_type, heel_colour, moul_sole, top_fox, top_colour, bottom_fox, bottom_colour, last_type, boots_height, size, total_pairs, date_required, lin_material, cuff_material, lace_colour, brand, colour, lacquer_finishing, safety, features, attachment, remarks, dept_name, pair, request_by, approval_status ) VALUES ('$fdate', '$ref_no', '$from', '$copy', '$description', '$buyer', '$ref', '$potential_annual', '$target_price', '$market_app', '$instruct', '$comp_colour', '$pattern', '$sole_colour', '$calender_pattern', '$heel_type', '$heel_colour', '$moul_sole', '$top_fox', '$top_colour', '$bottom_fox', '$bottom_colour', '$last_type', '$boots_height', '$size', '$total_pairs', '$date_required', '$lin_material', '$cuff_material', '$lace_colour', '$brand', '$colour', '$lacquer_finishing', '$safety', '$features', '$attachment', '$remarks', '$department', '$pair', '$request_by', 'pending')";
 $result=mysql_query($sql);
        if($result)
        {
             echo "Requisition Successfully Added!";
        }
        else
        {
             echo "failed";
        }
    }
?>
<table width="1028" height="1181" border="2" align="center" cellpadding="2" cellspacing="3" cols="2" bgcolor="#C0C0C0">
  <td width="1012" height="20"><center><font color="#0000FF"><strong>SAMPLE REQUISITION FORM</strong></font></center>
  <tr>
<form action="form.php" method="post">
<br>
<tr>
                <td height="20"><b><strong>Filed Date :</span></div>
                </strong>
 <input name="fdate" type="text" id="day" value="<?php echo date('Y-m-d'); ?>" size="10" maxlength="15"  readonly />
                <b> <strong>Reference No :</strong><input name="ref_no" type="text" id="ref_no" value="" size="10" maxlength="10" /></td>
          </tr>
<tr>
<td height="20"><strong><b>From :</strong>
  <input type="text" name="from" size="28" value=""/>  
   <b> <strong>Copy :</strong>
   <input type="text" name="copy" size="28" value=""/>
   <b> <strong>To : <em>Product Department</em></strong></td></tr>
  <tr>
<td height="30"><b><strong>Description :
      </strong>
  <label><br>
      <input name = "description[]" type = "checkbox" value ="safety" onclick="enableElement(this.form.elements['inp1']);"  />
      SAFETY </label>
    <label> 
      <input name = "description[]" type = "checkbox" value = "work" onclick="enableElement(this.form.elements['inp2']);" />
      WORK </label>
    <label> 
      <input name= "description[]" type ="checkbox" value="yachting" onclick="enableElement(this.form.elements['inp3']);"/>
      YACHTING </label>
    <label> 
      <input name="description[]" type ="checkbox" value="golf" onclick="enableElement(this.form.elements['inp4']);"/>
      GOLF </label>
    <label> 
      <input name="description[]" type = "checkbox" value="hiking" onclick="enableElement(this.form.elements['inp5']);"/>
      HIKING </label>
    <label> 
      <input name="description[]" type="checkbox" value="ladies" onclick="enableElement(this.form.elements['inp6']);"/>
      LADIES</label>
      <input name="description[]" type="checkbox" value="children" onclick="enableElement(this.form.elements['inp7']);"/>      
      CHILDREN</label>
    <label> 
      <input name="description[]" type="checkbox" value="hunting" onclick="enableElement(this.form.elements['inp8']);"/>
      HUNTING </label>
    <br>
    <label> 
      <input name="description[]" type="checkbox" value="wader" onclick="enableElement(this.form.elements['inp9']);"/>
      WADER </label>
      <label>
    <input type="checkbox" name="description[]" value ="others" onclick="enableElement(this.form.elements['inp10']);" />OTHERS :
<input type="text" name="inp10" size="30" disabled="disabled"/>
</label>
</td></tr>
<tr>
<td height "30"><strong><b>Buyer (Company Address/ Country) :</strong>
  <textarea name="buyer" type="text" size="30" maxlength="30"></textarea>
  <strong><b> Reference :</strong>
  <input name="ref" type="text"  value="" size="30" maxlength="30"  />
  </tr>
<tr><td height="20"><strong><b>Potential Annual Volume :</strong>
  <input type="text" name="potential_annual" size="20" value=""/>
      <b><strong>Target Price :</strong>
      <input type="text" name="target_price" size="20" value=""/> 
  <b> <strong>Market Application :</strong>  <input type="text" name="market_app" size="30" value=""/></td>
  </tr>
<tr>
<td height="57"><b><strong>Instruction :
</strong>
  <label><br>
  <input name = "instruct[]" type = "checkbox" value ="safety" onclick="enableElement(this.form.elements['inp1']);" />
      REFER FAX/ LETTER ATTACHED FOR FULL 
      DETAILS. </label> 
  <label>
      <input name="instruct[]" type="checkbox" value="duplicate" onclick="enableElement(this.form.elements['inp2']);"/> 
      DUPLICATE 
      <input name="instruct[]" type="checkbox" value="new" onclick="enableElement(this.form.elements['inp3']);"/>
NEW PRODUCT DEVELOPMENT</label>
   <label><br>
  </label>
  <label> 
     <input name="instruct[]" type="checkbox" value="art" onclick="enableElement(this.form.elements['inp4']);"/>
      MODIFICATION OF ART/MODEL : 
      <input type="text" name="inp4" size="30" disabled="disabled"/>
    </label>
  <label><br>
        <input name="instruct[]" type="checkbox" value="other" onclick="enableElement(this.form.elements['inp5']);"/>
      OTHERS :  <input type="text" name="inp5" size="30" disabled="disabled"/>
  </label></td>
</tr>
 <tr><td height="20"><center><font color="#0000FF"> 
   <strong><em>UPPER </em></strong></font>
 </center></td></tr> 
<tr>
  <td height="58"><b><strong>Compound / Colour :</strong>
    <input type="text" name="comp_colour" size="30" value=""/>  <br><b><strong>Pattern :  
        </strong>
    <label>
      <input name="pattern[]" type="checkbox" value="kid" onclick="enableElement(this.form.elements['inp1']);"/>KID </label>
      <label> 
        <input name="pattern[]" type="checkbox" value="nappa" onclick="enableElement(this.form.elements['inp2']);"/>NAPPA</label>
      <label> 
        <input name="pattern[]" type="checkbox" value="bull" onclick="enableElement(this.form.elements['inp3']);"/>BULL</label>
      <label> 
        <input name="pattern[]" type="checkbox" value="plain" onclick="enableElement(this.form.elements['inp4']);"/>PLAIN </label>
       <label>
         <input name="pattern[]" type="checkbox" value="others" onclick="enableElement(this.form.elements['inp5']);"/>
         OTHERS (Please Specify): 
         <input type="text" name="inp5" size="15" disabled="disabled"/>
       </label></td>
    </tr>
      <tr><td height="20"><center><font color="#0000FF"> 
        <strong><em>SOLE </em></strong></font>
      </center></td></tr>
    <tr>
  <td height="20"><b><strong>Sole Compound / Colour :</strong>
    <input type="text" name="sole_colour" size="30" value=""/>
<b> <strong>Calender Roll/Pattern : </strong>
<input type ="text" name="calender_pattern" size="30" value=""/></td></tr>
<tr>
  <td height="20"><strong><b>Heel Types :</strong>
    <input type="text" name="heel_type" size="30" value=""/>
<br><b><strong>Colour :</strong>
<label>
  <input name="heel_colour[]" type="checkbox" value="same_as_sole" onclick="enableElement(this.form.elements['inp1']);"/>Same as Sole </label>
<label>
<input name="heel_colour[]" type="checkbox" value="other" onclick="enableElement(this.form.elements['inp2']);" />OTHERS (Please Specify) : 
<input type="text" name="inp2" size="28" disabled="disabled"/>
</label></td></tr>
<tr>
<td height="20"><b><strong>Moulded Sole Type :</strong>  <input type="text" name="moul_sole" size="30" value=""/> </td>
</tr>
<tr> 
<td height="20"><b><strong>Top Foxing Pattern/Roll :</strong>
  <input type="text" name="top_fox" size="30" value=""/>
<br><b> <strong> Colour: </strong>
<label>
<input name="top_colour[]" type="checkbox" value="same_as_upper" onclick="enableElement(this.form.elements['inp1']);"/>Same as Upper</label>
<label>
<input name="top_colour[]" type="checkbox" value="other" onclick="enableElement(this.form.elements['inp2']);" />OTHERS (Please Specify) : <input type="text" name="inp2" size="28" disabled="disabled"/></label>
</td>
</tr>
<tr>
<td height="20"><strong><b>Bottom Foxing Pattern/Roll :</strong>
  <input type="text" name="bottom_fox" size="30" value=""/>
<br><b><strong>Colour : 
</strong>
<label>
  <input name="bottom_colour[]" type="checkbox" value="upper/sole" onclick="enableElement(this.form.elements['inp1']);"/> Same as Upper/Sole</label>
<label>
<input name="bottom_colour[]" type="checkbox" value="other" onclick="enableElement(this.form.elements['inp2']);"/> 
OTHERS (Please Specify) : 
<input type="text" name="inp2" size="28" value="" disabled="disabled"/></label> </td>
<tr>
<td height="20"><b><strong>Last Type :</strong>
  <input type="text" name="last_type" size="20" value=""/>
<b> <strong>Boots Height :</strong>
<input type="text" name="height" size="10" value=""/>
<b> <strong>Size :</strong>
<input type="text" name="size" size="10" value=""/> 
 <b> <strong>Total Pairs : </strong>
 <input type="text" name="total_pairs" size="10" value=""/>
<br><b><strong>Date Required :</strong> <input name="date_required" type="date" value=""/></td>
</tr>
<tr>
                <td height="20"><b><strong>Lining Material/ Colour :</strong> </span></div>
                <input name="lin_material" type="text"  value="" size="30"/></td>
<tr>
<td height="20"><b><strong>Cuff Material/Colour :
</strong>
  <label>
<input name="cuff_material[]" type="checkbox" value="n/a" onclick="enableElement(this.form.elements['inp1']);"/> N/A </label>
<label>
<input name="cuff_material[]" type="checkbox" value="" onclick="enableElement(this.form.elements['inp2']);"/><input type="text" name="inp2" size="30" value="" disabled="disabled"/></label>
</td></tr>
<tr>
<td height="20"><b><strong>Lace/Colour :</strong>
<label>
  <input name="lace_colour[]" type="checkbox" value="n/a" onclick="enableElement(this.form.elements['inp1']);"/> N/A </label>
<label>
<input name="lace_colour[]" type="checkbox" value="" onclick="enableElement(this.form.elements['inp2']);"/><input type="text" name="inp2" size="30" value="" disabled="disabled"/></label>
</td></tr>
  <tr>
    <td height="20"><b><strong>Brand :</strong>   <input type="text" name="brand" size="30" value=""/> 
      <b><strong>Colour :</strong>   <input type="text" name="color" size="30" value=""/></td>
    </tr>
<tr>
<td height="20"><b><strong>Lacquer Finishing :</strong>
<label> 
  <input name = "lacquer_finishing[]" type = "checkbox" value ="gloss" onclick="enableElement(this.form.elements['inp1']);"/>
  GLOSS </label>
    <label> 
      <input name = "lacquer_finishing[]" type = "checkbox" value = "dull" onclick="enableElement(this.form.elements['inp2']);"/>
      DULL </label>
    </td></tr>
<tr>
<td height="20"><b><strong>Safety Standards to Confirm :</strong>
<label><input name="safety[]" type="checkbox" value="n/a" onclick="enableElement(this.form.elements['inp1']);"/>N/A</label>
<label><input name="safety[]" type="checkbox" value="en-" onclick="enableElement(this.form.elements['inp2']);"/>EN-
<input type="text" name="inp2" disabled="disabled" size="10"></label>
<label><input name="safety[]" type="checkbox" value="csa" onclick="enableElement(this.form.elements['inp3']);"/>CSA</label>
<label><input name="safety[]" type="checkbox" value="astm" onclick="enableElement(this.form.elements['inp4']);"/>ASTM</label>
<label><input name="safety[]" type="checkbox" value="sirim" onclick="enableElement(this.form.elements['inp5']);"/>SIRIM</label>
<label>
<input name="safety[]" type="checkbox" value="other" onclick="enableElement(this.form.elements['inp6']);"/>Others:<input type="text" name="inp6" size="10" disabled="disabled"/>
</label></td>
</tr>
<tr>
<td height="75"><b><strong>NotWithStanding 15.0 Above, Other Features Required :
</strong>
  <label><br>
<input name="features[]" type="checkbox" value="none" onclick="enableElement(this.form.elements['inp1']);"/>NONE</label>
<label>
<input name="features[]" type="checkbox" value="steel_toe_cap" onclick="enableElement(this.form.elements['inp2']);"/>STEEL TOE CAP</label>
<label>
<input name="features[]" type="checkbox" value="steel_mid_sole" onclick="enableElement(this.form.elements['inp3']);"/>STEEL MID SOLE</label>
<label>
<input name="features[]" type="checkbox" value="steel_shank" onclick="enableElement(this.form.elements['inp4']);"/>STEEL SHANK</label>
<label>
<input name="features[]" type="checkbox" value="anti_static" onclick="enableElement(this.form.elements['inp5']);"/>ANTI-STATIC</label>
<label>
  <input name="features[]" type="checkbox" value="fire_retardant" onclick="enableElement(this.form.elements['inp6']);"/>
  FIRE RETARDANT</label>
<label>
  <br>
  <input name="features[]" type="checkbox" value="oil_resistant_sole_upper" onclick="enableElement(this.form.elements['inp7']);"/>OIL RESISTANT SOLE & UPPER</label>
<label>
  <input name="features[]" type="checkbox" value="chainsaw_protection" onclick="enableElement(this.form.elements['inp8']);"/>
CHAINSAW PROTECTION</label>
<label>
  <input name="features[]" type="checkbox" value="anti_slip_sole" onclick="enableElement(this.form.elements['inp9']);"/>
  ANTI-SLIP SOLE</label>
<label>
  <input name="features[]" type="checkbox" value="electric_shock_resistant" onclick="enableElement(this.form.elements['inp10']);"/>ELECTRIC SHOCK RESISTANT</label>
<label>
  <br>
  <input name="features[]" type="checkbox" value="other" onclick="enableElement(this.form.elements['inp11']);"/>
  OTHERS (please specify) :
<input type="text" name="inp11" size="38" disabled="disabled"/></label>
</td></tr>
<tr>
<td height="20"><b><strong>Sketches/Drawings Attached :
</strong>
  <label> 
      <input name = "attachment[]" type = "radio" value ="yes" checked/>YES</label>
      <label>
      <input name="attachment[]" type="radio" value="no"/>NO</label>
</td>      
</tr>
<tr>
  <td height="45"><b><strong>Other Description/Remarks :</strong>  <textarea name="remarks" type="text" rows="5" cols="40"></textarea></td>
</tr>
<tr>
<td height="20"><center><font color="#0000FF"><em><strong>#Sample Distribution</strong></em></font>
</center></td> 
</tr>
<tr>
<td height="20"><strong><strong>TO :</strong><select name = "department" >
  <option selected> Department </option>
  <option> Marketing Department</option>
  <option> Technical Department </option>
  <option> Product Development Section</option>
</select> 
  <strong><b> Pairs :</strong>
  <input type="text" name="pair" size="10"/>
  <br>
<strong><b> Requested By :</strong>  <input type="text" name="request_by" size="30" value=""/></td>
</tr>
<tr>
<tr>
</tr>
<tr>
<td>
<label>
<input name="notify" type="checkbox" value="notify" checked/> 
<em><strong>Send notification for approval. </strong></em><strong></strong></label>
(Make sure it's always checked!)</td>
</tr>
<tr>
<td height="30"><center><input type = "submit" value = "Submit Requisition"  name="Submit" /></center></td>
<input type="hidden" name="submitted" />
</tr>
</form>
</tr>
</table>
<?php
echo "<br>";echo "<br>";echo "<br>";echo "<br>";echo "<br>";echo "<br>";
include('includes/footer.html');
?>
</body>
</html>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How to insert data from multiple checkbox values

Post by Celauran »

Code: Select all

error_reporting(0);
Stop doing that and "it's not doing anything" will magically become meaningful error messages. Once we have an idea what we're looking for, we'll be better able to help you.
Post Reply