Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2012
    Thanked 0 Times in 0 Posts

    need help inserting checkbox to DB

    Hi, I'm still new at PHP and I would like to know how to insert the CHECKBOX VALUE in my database? I don't know what i'm doing wrong... Any help will really be appreciated.. Thanks!

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    	require_once 'library/database.php';
    	require_once 'library/admin_config.php';
    	$fpay='Full Payment';
    	$sql="INSERT INTO invoice (part1,part2,part3,part4,part5,part6,part7,part8,amt1,amt2,amt3,amt4,amt5,amt6,amt7,amt8,vat1,vat2,vat3,vat4,vat5,vat6,vat7,vat8,totamt1,totvat1,received,addr,sum,orno,total,chckcash,chkcheck,fpay) VALUES ('$part1','$part2','$part3','$part4','$part5','$part6','$part7','$part8','$amt1','$amt2','$amt3','$amt4','$amt5','$amt6','$amt7','$amt8',$vat1','$vat2','$vat3','$vat4','$vat5','$vat6','$vat7','$vat8','$totamt1','$totvat1','$received','$addr','$sum','$orno','$total','$chkcash','$chkcheck','$fpay')";
    	$res=mysql_query($sql) or die("Cannot Insert to Database! ".mysql_error());
    	$report = "Successfully added!"; //shows message
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Invoicing Page</title>
    <form method="post" action="">
    <div id="tables" style="position:relative; left:-320px; top:40px;">
    <table width="220" border="1">
      <td width="220">In Payment of the Following:</td>
    <table width="220" border="1">
      <td width="75"><center>Particulars</center></td>
      <td width="68"><center>Amount</center></td>
      <td width="35"><center>VAT</center></td>
      <td width="75"><input style="width:75px" name="part1" id="part1" type="text" value="<?php echo $part1;?>"  /></td>
      <td><input style="width:68px" name="amt1" id="amt1" value="<?php echo $amt1;?>" type="text" /></td>
      <td><input style="width:35px" name="vat1" id="vat1" value="<?php echo $vat1;?>" type="text" /></td>
      <td width="75"><input style="width:75px" name="part2" value="<?php echo $part2;?>" id="part2" type="text" /></td>
      <td><input style="width:68px" name="amt2" id="amt2" value="<?php echo $amt2;?>"type="text" /></td>
      <td><input style="width:35px" name="vat2" id="vat2" value="<?php echo $vat2;?>" type="text" /></td>
      <td width="75"><input style="width:75px" name="part3" value="<?php echo $part3;?>" id="part3" type="text" /></td>
      <td><input style="width:68px" name="amt3" id="amt3" value="<?php echo $amt3;?>" type="text" /></td>
      <td><input style="width:35px" name="vat3" id="vat3" value="<?php echo $vat3;?>" type="text" /></td>
      <td width="75"><input style="width:75px" name="part4" value="<?php echo $part4;?>" id="part4" type="text" /></td>
      <td><input style="width:68px" name="amt4" id="amt4" value="<?php echo $amt4;?>" type="text" /></td>
      <td><input style="width:35px" name="vat4" id="vat4" value="<?php echo $vat4;?>" type="text" /></td>
      <td width="75"><input style="width:75px" name="part5" value="<?php echo $part5;?>" id="part5" type="text" /></td>
      <td><input style="width:68px" name="amt5" id="amt5" value="<?php echo $amt5;?>" type="text" /></td>
      <td><input style="width:35px" name="vat5" id="vat5" value="<?php echo $vat5;?>" type="text" /></td>
      <td width="75"><input style="width:75px" name="part6" value="<?php echo $part6;?>" id="part6" type="text" /></td>
      <td><input style="width:68px" name="amt6" id="amt6" value="<?php echo $amt6;?>" type="text" /></td>
      <td><input style="width:35px" name="vat6" id="vat6" value="<?php echo $vat6;?>" type="text" /></td>
      <td width="75"><input style="width:75px" name="part7" id="part7" value="<?php echo $part7;?>" type="text" /></td>
      <td><input style="width:68px" name="amt7" id="amt7" value="<?php echo $amt7;?>" type="text" /></td>
      <td><input style="width:35px" name="vat7" id="vat7" value="<?php echo $vat7;?>" type="text" /></td>
      <td width="75"><input style="width:75px" name="part8" value="<?php echo $part8;?>" id="part8" type="text" /></td>
      <td><input style="width:68px" name="amt8" id="amt8" value="<?php echo $amt8;?>" type="text" /></td>
      <td><input style="width:35px" name="vat8" id="vat8" value="<?php echo $vat8;?>" type="text" /></td>
      <td><input style="width:68px" name="totamt1" id="totamt1" value="<?php echo $totamt1;?>" type="text" /></td>
      <td><input style="width:35px" name="totvat1" id="totvat1" value="<?php echo $totvat1;?>" type="text" /></td>
    <table width="220" border="1">
    <tr><td><center>FORMS OF PAYMENT:</center></td></tr>
    <table width="220" border="1">
      <td width="75">Cash  :<input type="checkbox" name="chkcash" id="chkcash" value="
    PHP Code:
    <?php echo $chkcash;?>
    "/></td> <td width="68">&nbsp;</td> <td width="35">&nbsp;</td> </tr> <tr> <td>Check:<input type="checkbox" name="chkcheck" id="chkcheck" value="
    PHP Code:
    <?php echo $chkcheck;?>
    " /></td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> </table> <table width="220" border="1"> <tr> <td><b>TOTAL:</b></td> <td><input style="width:100px" type="text" name="total" value="<?php echo $total;?>" /></td> </tr> </table> </div> <div id="or" style="position:relative; top:-400px; left:30px; width:400px;"> <table > <tr> <td><font size="+1"><strong>OFFICIAL RECIEPT</strong></font></td> </tr> </table> <table> <tr> <td><label>Received from: </label></td> <td><input type="text" name="received" id="received" value="<?php echo $received;?>" /></td> </tr> <tr> <td><label>Address: </label></td> <td><input type="text" name="addr" id="addr" value="<?php echo $addr;?>" /></td> </tr> <tr> <td><label>The sum of Pesos: </label></td> <td><input type="text" name="sum" id="sum" value="<?php echo $sum;?>" /></td> </tr> </table> <br /><br /> in payment of account described hereon.<br /><br /> <input type="checkbox" name="fullpay" id="fpay" value="<?php echo $fpay;?>" /><label>FULL PAYMENT</label><br /><br /> <label>By: </label><input type="text" /> </div> <div id="orno" style="position:relative; top:-650px; left:250px; width:200px;"> No.<input type="text" name="orno" value="<?php echo $orno;?>" /> </div> <div id="button" style="position:relative; top:-250px; left:250px;"> <input type="submit" name="save" id="save" class="btnn" value="Save" /> <input type="button" class="btnn" value="Back" /> </div> </form> </body> </html>
    Last edited by evilbugoy; 10-19-2012 at 07:53 AM.

  2. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Thanked 1,008 Times in 1,005 Posts
    First straighten up your HTML. Many errors; tables wrong.
    In your php you are setting all variables to empty and inserting that into DB. You must use the $_POST[] to set these variables. And checkbox don't work the way you think it does. Look these things up.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts