Prevent double insert at same time |
Hi , today i check if there are some record inserted at same time in a db's table and i have 21 record duplicated 8 on 2022, 12 on 2023 and 1 on 2024 .I reduce this effect by adding a js working when i push submit button (disabling button and showing a gif) at half of 2024 but i have a duplicate on december 2024 .
How can I completely avoid this problem?
Use redirect() after sending the form: https://codeigniter.com/user_guide/outgo...l#redirect
(01-14-2025, 09:18 AM)michalsn Wrote: Use redirect() after sending the form: https://codeigniter.com/user_guide/outgo...l#redirect Always i redirect after submit , this is an example : Code: $db = \Config\Database::connect(); But this is not the solution...
1. What do you mean by duplicated records?
2. Are you sending a form? 3. Are you using JS to send form data?
using a js client side verification isn't efficient nor secure.
to prevent the form being submited twice with same data one way is to use CI4 CSRF security set Config/Security.php $regenerate = true put a CSRF token in your form set a CSRF filter on your POST route or check CSRF token in your controller on POST https://codeigniter.com/user_guide/libra...urity.html you may also set the db column(s) as unique so if one user try to submit dupplicate data with a valid CSRF the db will not accept them
You posted the same answer as 4 hours ago. Please show me your actual JS code that handles form submission.
(01-16-2025, 04:48 AM)michalsn Wrote: You posted the same answer as 4 hours ago. Please show me your actual JS code that handles form submission. sorry i make a mistake : button to submit Code: <div class='text-right mt-4'> script Code: $("#bottone_invio_form").click(function() { |
Welcome Guest, Not a member yet? Register Sign In |