Web Analytics Made Easy -
StatCounter Sending Dynamic Form Data To Mysql via PHP - CodingForum


No announcement yet.

Sending Dynamic Form Data To Mysql via PHP

  • Filter
  • Time
  • Show
Clear All
new posts

  • Sending Dynamic Form Data To Mysql via PHP

    I have created a dynamic form and i am trying to store the form data to mysql with php. But data doesnt get saved to database. I am posting my all codes below. I want to know how can i solve this problem, or where are my faults and how can i have an accurate form.. I am new to this and out of ideas.

    Here is my form code:

    <form name="newbillform" method="POST" action="save_purchase_details.php">
       <table style=" border:1px solid black" cellpadding="5px" cellspacing="0px"
       align="center" border="0">
       <td colspan="4" style="background:#0066FF; color:#FFFFFF; fontsize:
       20px" align="center">ADD NEW PURCHASE RECORD</td></tr>
       <td><input type="date" name="p_date"/></td></tr>
       <td>Invoice Number:</td>
       <td><input type="text" name="invoice_no" size="50"></td></tr>
       <td><input type="text" name="balance" size="50"></td></tr>
    <h2 style="padding-left:10px;">Enter Product Details Below:-</h2>
    <table id="product_details" style="margin-top:8px;" align='center' border='1' width="900px">
       <tr id="row1">
       <td><input type="text" name="qty[]" placeholder="Quantity" size="6"></td>
       <td><input type="text" name="pack[]" placeholder="Pack" size="6"></td>
       <td><input type="text" name="item_name[]" placeholder="Item Name" size="16"></td>
       <td><input type="text" name="batch[]" placeholder="Batch" size="6"></td>
       <td><input type="text" name="expiry[]" placeholder="Expiry" size="6"></td>
       <td><input type="text" name="mrp[]" placeholder="M.R.P" size="6"></td>
       <td><input type="text" name="rate[]" placeholder="Rate" size="6"></td>
       <td><input type="text" name="vat[]" placeholder="VAT" size="6"></td>
       <td><input type="text" name="discount[]" placeholder="Discount" size="6"></td>
       <td><input type="button" class="button-add-row" onClick="add_row();" value="ADD ROW" size="8"></td>
          <input type="submit" name="submit_row" value="SUBMIT">
    Here is the javascript code...

    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
    function add_row()
    $rowno=$("#product_details tr").length;
     $("#product_details tr:last").after("<tr id='row"+$rowno+"'><td><input type='text' name='qty[]' placeholder='Quantity' size='6'></td><td><input type='text' name='pack[]' placeholder='Pack' size='6'></td><td><input type='text' placeholder='Item Name' name='item_name[]' size='16'></td><td><input type='text' name='batch[]' placeholder='Batch' size='6'></td><td><input type='text' name='expiry[]' placeholder='Expiry' size='6'></td><td><input type='text' name='mrp[]' placeholder='M.R.P' size='6'></td><td><input type='text' name='rate[]' placeholder='Rate' size='6'></td><td><input type='text' name='vat[]' placeholder='VAT' size='6'></td><td><input type='text' name='discount[]' placeholder='Discount' size='6'></td><td><input type='button' class='button-add-row' value='DELETE' onclick=delete_row('row"+$rowno+"')></td></tr>");
    function delete_row(rowno)
    Here is the PHP code...

    $connect = mysql_connect("localhost","root","") or die(mysql_error());
    mysql_select_db("store_records",$connect) or die(mysql_error());
     $query =mysql_query("insert into bill_records values('', '$p_date', '$invoice_no', '$balance', '$qty','$pack','$item_name', '$batch', '$expiry', '$mrp', '$rate', '$vat', '$discount', '$amount', '$grand_total')");	 
    It would be of great help.. Thank you!

  • #2
    Why put your code in php tags and then put that in code tags? - You've just made it pretty hard to read your php code.
    "Tango says double quotes with a single ( ' ) quote in the middle"
    '$Name says single quotes with a double ( " ) quote in the middle'
    "Tango says double quotes ( \" ) must escape a double quote"
    '$Name single quotes ( \' ) must escape a single quote'


    • #3
      After the mysql_query add
      That will give you the mysql error.

      Is this a hobby project? If not then you have some serious security holes in there.
      Don't use old mysql library
      The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets
      When a white horse is not a horse