I have an edit form (change the quantity and delete) of the goods selected by the user. The form itself is formed by a cycle, that is, there are 2 inputa:

<input type="number" name="col" class="coltbl" value="<?php echo $row['tvr'];?>" /> <input type="checkbox" name="delite" value="<?php echo $row['tvrid'];?>" /> 

Important: the "Save" button is outside the cycle - the total for the entire withdrawal of goods.

The task is that it is not clear how to initialize the edited product in the handler. And if the checkbox carries the necessary information in its arsenal via value (this is the id of the product being edited), then here’s the first step in the problem: the value is the quantity and identifying it with a specific product is problematic ...

Remembered about arrays:

 name="col[<?php echo $tvrid;?>]" 

And now I do not understand what to do next in the handler. Thank!

  • one
    > delite delete It’s best to do this: <input type = "number" name = "products [<? = $ row ['tvrid']?>] [number]" class = "coltbl" value = "<? = $ row ['tvr']?> "/> <input type =" checkbox "name =" products [<? = $ row ['tvrid']?>] [delete] "value =" true "/> After that in $_POST will turn out to be a pretty array of products , in which the keys are the product IDs. - etki
  • understood only one thing: you need to understand what arrays are. went to read. if it used to be at least vague, but nevertheless it is clear what to do in the handler, now it is not clear at all. - Azat Khanov

1 answer 1

All figured out! Thank you very much! Did so:

 if (isset($_POST['save'])) { $products=$_POST['products']; foreach ($products as $id => $value) { $tvr=strip_tags(trim($value['number'])); mysql_query("UPDATE cart SET tvr='".$tvr."' WHERE tvrid='".$id."'"); if (isset($value['delete'])) { mysql_query("DELETE FROM cart WHERE tvrid='".$id."'");} }}