Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li>First of all, don't include single quotes in a double quote string when you're referencing arrays, you risk to have an "encapsed string" error.</li> <li> You also include a double quoted string in <code>"item_qty"</code> which will likely result in an error.</li> <li>Close the <code>option</code> tags with <code>/&gt;</code> as best practice.</li> <li>Your <code>LABEL</code> tag is not used properly. The correct syntax is: <code>&lt;label for='html_element_id'&gt;My pretty label&lt;/label&gt; &lt;input id='html_element_id ... (my form control) ... /&gt;</code> and it's pretty useless (though always more semantic and structured) with other controls than checkboxes or radios.</li> <li> You may cosider using a <code>TABLE</code> instead of <code>P</code> tags to have everything lined up. Better, you could use CSS to line up things, much better practice.</li> <li><p>If you hard-code the choices it can be difficult to handle requirement changes: what if you need quantities from 1 to 10? What if you choose to use a textbox instead of a <code>SELECT</code>?</p> <pre><code>while($t_row = mysql_fetch_assoc($get_items)) { // Generate quantity string - can change the $qty string // for any imput method you like $qtyName = "item_qty[]"; $qty = "&lt;select name='" . $qtyName . "'&gt;"; for ($i=1; $i&lt;6; $i++) { // close the option tag as best practice! $qty .= "&lt;option value='" . $i . "' /&gt;"; } $qty .= "&lt;/select&gt;"; echo sprintf("&lt;p&gt;%s &lt;input type='text' READONLY name='item_price[]' value='%s' /&gt;&lt;/label&gt; &lt;input type='text' READONLY name='item_fees[]' value='$s' /&gt; " . $qty . "&lt;/p&gt;", $t_row['item_price'], $t_tow['item_fee']); } </code></pre></li> </ol> <p>Collecting the data would be simple:</p> <pre><code>$sum = 0; $fees = $_POST['item_fee']; $qtys = $_POST['item_qty']; $prices = $_POST['item_price']; $total = count($prices); for ($i = 0; $i&lt;total; $i++) { $item_fee = $fees[$i] + 0; // trick to filter only numerical values and avoid data tampering $item_price = $price[$i] + 0; $item_quantity = $qtys[$i] + 0; $item_total = $item_price + $item_fee * $item_quantity; $sum += $item_total; } </code></pre> <p>I too agree that having a direct representation of prices in you form can lead anyway to data tampering, the user that suggested you to check against a database has given a very wise advice.</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.
    1. VO
      singulars
      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