Can anyone please help me with this one? i have successfully save data in my form but i can only do it in a single row.. please help me how to add rows automatically, how to auto number the Item No., how to auto-total the Quantity column and the Unit Cost Column to Total Cost and lastly an editable form incase the user put the wrong items and save it to mysql. thanks in advance and more power!

Edited by genegavino: wrong spelling

4 Years
Discussion Span
Last Post by diafol

Perhaps you'd like to supply more info like:

1) Form code markup
2) Form handling code (php)
3) MySQL DB table structure
4) Any other relevant code/info

You assume that we have crystal balls.


You need to set the row fields name as an array.
You should know the javascript or jquery for appent each rows without page load.


sorry my mistake. here is my code.

<form action="save.php" method="post">

    <table width="100%" border="0" cellpadding="1" cellspacing="0" class="normal-text" align="left">
    <tr align="center">
    <th width="6%" class="forhead" style="white-space:nowrap;">No.</th>
    <th width="10%" class="forhead" style="white-space:nowrap;">Unit</th>
    <th width="20%" class="forhead" style="white-space:nowrap;">Description</th>
    <th width="10%" class="forhead" style="white-space:nowrap;">Quantity</th>
    <th width="12%" class="forhead" style="white-space:nowrap;">Unit Cost</th>
    <th width="12%" class="forhead" style="white-space:nowrap;">Total Cost</th>



    <input type="text" name="itemNo" size="4" />
    <input type="text" name="unit" size="10" />
    <input type="text" name="description" size="27" />
    <input type="text" name="qty"  size="10" id="number" onchange="if (/^\.?$/.test(this.value) || !/^-?\d*\.?\d*$/.test(this.value)) {alert('aduy!'); this.value=''; this.focus()}"/>
    <input type="text" name="rate" size="13" id="number" onchange="if (/^\.?$/.test(this.value) || !/^-?\d*\.?\d*$/.test(this.value)) {alert('aduy!'); this.value=''; this.focus()}"//>
    <input type="text" name="amt"  size="14" id="number" onchange="if (/^\.?$/.test(this.value) || !/^-?\d*\.?\d*$/.test(this.value)) {alert('aduy!'); this.value=''; this.focus()}"//>

    <INPUT type='submit' value='S A V E'/>


    $con = mysql_connect("localhost","user","user");
    if (!$con)
      die('Could not connect: ' . mysql_error());

    mysql_select_db("sales_db", $con);

    $sql="INSERT INTO Items (itemNo, Unit, Description, Quantity, Price, Total, ORNumber)

    if (!mysql_query($sql,$con))
      die('Error: ' . mysql_error());


Edited by genegavino


A. Your html is shot to hell. Multiple </html> tags with inexplicable <table> closures.

B. Your SQL is using raw POST vars - unsanitized and highly dangerous - don't do it! Neither is there any validation - you could be shoving any old rubbish into the DB.

C. What are you trying to achieve with this particular JS:

if (/^\.?$/.test(this.value) || !/^-?\d*\.?\d*$/.test(this.value)) {alert('aduy!'); this.value=''; this.focus()}

//As you're repeating this all over the place, it should go into a js function.

D. Inline styles and html styling attributes should be a thing of the past. You seem to have 'included the kitchen sink'. Maybe de-cluttering your html will enable you to focus on producing valid HTML in the first instance.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.