Hello.

There was a question of saving the form, where a bunch of fields. It works, but I'm not sure what I'm doing right.

For example, we have a form

<form action="" method="post"> <!-- ЭТО ВСЕ В ЦИКЛЕ --> <input name="1[firstname]" value="" /> <input name="1[secondname]" value="" /> <input name="1[nlastame]" value="" /> <input name="1[phone]" value="" /> <input name="1[address]" value="" /> <!-- ЭТО ВСЕ В ЦИКЛЕ --> <input type="submit" /> </form> 

Where 1 is id

Next, I process, let's say

 foreach ($_POST AS $id => $value) { $id - ID записи, по которой я обновляю данные $value - содержит массив уже со значениями mysql_query(...запрос обновления...); } 

What can be done here not to make a request in a loop when updating and is it possible at all?

At the same time, it turns out that some more fields need to be checked for fullness. You can of course muddish the validation through js, but it would also be useful for the handler to check which fields are needed. I don’t understand how to display errors if the field is not filled, and the rest are filled. Run to save and check for fullness? Can someone tell me how this can be done?

It turns out that how many iterations will be, there will be so many requests that, it turns out to be expensive, if you set 30 per page and in each 10 fields.

That turns out 30 requests and 300 fields. This is if you need to update in one table.

I would appreciate advice.

  • one
    why 300 fields? how strange it is. But if you choose between one big request or a hundred small ones, then I would choose the first one. The load on the network and less on the server. - KoVadim
  • Validation on the client side is not enough, the client can simply disable js or even intentionally distort data in search of vulnerabilities. - VladD
  • This extension is not recommended when writing new code. Use mysqli or PDO_MySQL instead. See also the MySQL API overview for more detailed information on choosing the MySQL API. php.net/manual/ru/intro.mysql.php - zb '
  • @KoVadim is a mass edit of the data in the table. For example, a table where there is a list of users. And in order not to constantly make unnecessary gestures to open editing pages, I decided to try en masse. It's more convenient and saves time. @VladD is admin panel. although I have indicated that I want to check not only on the client. @eicto redoing something is not an option in this direction. I am writing not new, but I am trying to improve the management of what is already there. - drop_off
  • @SilverIce is a good idea! The result will be identical, there is also no need to press the button. I'm going to try now. - drop_off

1 answer 1

Mass editing of the table is better done through ajax - updating only what the user has updated to the database ... Well, validation will be slightly more convenient. If you need a record just by pressing the "write" button, then you can accumulate in a session or in an array on the client side.

AJAX is unlikely to reduce server load. But visibility will be higher.