Note that there are some explanatory texts on larger screens.

plurals
  1. POForm loop db insertion + javascript altering
    primarykey
    data
    text
    <p>I basically need to check if there is an easier way to do this before I rewrite all the code. I have a fairly large form that I have each input named with []'s on the end so I can loop through via php for easy insertion. </p> <pre><code> &lt;input type="hidden" name="currentdate[]" value="&lt;?php echo date('mdY'); ?&gt;"&gt; &lt;td&gt;&lt;input style="width: 50px" type="text" name="jackname[]" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input style="width: 20px" type="text" name="jackkey[]" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input style="width: 50px" type="text" name="jackbeg[]" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input style="width: 50px" type="text" name="jackend[]" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input style="width: 50px" type="text" name="jackbegveh" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input style="width: 50px" type="text" name="jackbegmon[]" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input style="width: 50px" type="text" name="jackendveh" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input style="width: 50px" type="text" name="jackendmon[]" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input style="width: 50px" type="text" name="jacktx" disabled /&gt;&lt;/td&gt; </code></pre> <p>There are quite a few more fields but you get the idea. I then use</p> <pre><code>foreach ($_POST['jackname'] as $row=&gt;$name) { $jackname = $name; $date = $_POST['currentdate'][$row]; $jackkey = $_POST['jackkey'][$row]; $jackbeg = $_POST['jackbeg'][$row]; $jackend = $_POST['jackend'][$row]; $jackbegveh = $_POST['jackbegveh'][$row]; $jackbegmon = $_POST['jackbegmon'][$row]; $jackendveh = $_POST['jackendveh'][$row]; $jackendmon = $_POST['jackendmon'][$row]; $jacktx = $_POST['jacktx'][$row]; if ($jacktx == '') { $jacktx = '0'; } if (empty($jackkey)) { echo 'Skipped empty! &lt;br /&gt;'; } else { mysql_query("INSERT INTO `ticket_counts_jackson` VALUES('', '" . $date . "', '" . $jackname . "', '" . $jackkey . "', '" . $jackbeg . "', '" . $jackend . "', '" . $jackbegveh . "', '" . $jackbegmon . "', '" . $jackendveh . "', '" . $jackendmon . "', '" . $jacktx . "')", $mysql_link) or die(mysql_error()); echo 'Added the info the db! &lt;br /&gt;'; } } </code></pre> <p>I use the above to loop through the form and add it to the database. Now for my main question. I also want to add in some javascript to do a little math. Basically <code>($jackendveh - $jackbegveh) - ($jackendmon - $jackbegmon)</code> and have that displayed in jacktx. Currently the only way I know of adding in the math calculations is to rename each input to a unique name and then rewrite my insert from 1 insert to 8 inserts. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload