Note that there are some explanatory texts on larger screens.

plurals
  1. POMysql edit users orders they have placed
    primarykey
    data
    text
    <p>Hi i'm working through an ordering system, i've got the placing an order done and its going into the database fine, but i'm struggling to think how to let the user edit the order once its been inserted.</p> <p>This is how i grab the order from the page and send it to a PHP insert script:</p> <pre><code>$('#submit').live('click',function(){ var postData = {}; $('#items tr').not(':first').each(function(index, value) { var keyPrefix = 'data[' + index + ']'; postData[keyPrefix + '[supp_short_code]'] = $(this).closest('tr').find('.supp_short_code').text(); postData[keyPrefix + '[project_ref]'] = $(this).closest('tr').find('.project_ref').text(); postData[keyPrefix + '[om_part_no]'] = $(this).closest('tr').find('.om_part_no').text(); postData[keyPrefix + '[description]'] = $(this).closest('tr').find('.description').text(); postData[keyPrefix + '[quantity_input]'] = $(this).closest('tr').find('.quantity_input').val(); postData[keyPrefix + '[cost_of_items]'] = $(this).closest('tr').find('.cost_of_items').text(); postData[keyPrefix + '[cost_total_td]'] = $(this).closest('tr').find('.cost_total_td').text(); }); $.ajax ({ type: "POST", url: "order.php", dataType: "json", data: postData, cache: false, success: function() { alert("Order Submitted"); } }); }); </code></pre> <p>And this is the PHP insert:</p> <pre><code>if (isset($_POST['data']) &amp;&amp; is_array($_POST['data'])) { foreach ($_POST['data'] as $row =&gt; $data) { $result = mysql_query("INSERT INTO orders (id,order_id,project_ref,supp_short_code,om_part_no,description,quantity,cost_of_items,cost_total) VALUES('', '".$order_id."', '".$data['project_ref']."', '".$data['supp_short_code']."', '".$data['om_part_no']."', '".$data['description']."', '".$data['quantity_input']."', '".$data['cost_of_items']."', '".$data['cost_total_td']."') ") or die(mysql_error()); } } </code></pre> <p>So i'm aware this isnt the cleanest way to do it, so thats why i'm struggling to find a clean way to let them edit the order. I know how to do "Update" queries but its the fact that i've used for each loops and arrays to insert the order? Anyone have any advice from the code above on what to present to the user?</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.
 

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