Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9130187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:54:53+00:00 2026-06-17T07:54:53+00:00

I have a database, and one table (innoDB): table. Row in this table is:

  • 0

I have a database, and one table (innoDB): table.

Row in this table is: m1 and m2.

I have 2 submit buttons on one page.

Submit 1 does this:

Database::q('UPDATE table SET m1 = ?s, m2 = ?i WHERE id = ?i', $n, 0, $ID);

Submit 2 does this:

Database::q('UPDATE table SET m2 = ?s WHERE id = ?i', $n2, $ID);

The problem: if a user submits both forms at det same time. Lets say 100 000 ($n) on submit 1 and 50 ($n2) on submit 2.
The result will be after updates: 99 950 on m1 and 100 000 on m2.

How can i prevent this?
I tried using transactions but its still not working properly.

Is this syntax correct? I dont understand when to use whitch one: exec, query, execute?

try {
   Database::beginTransaction();
   Database::q('..');
   Database::commit();
} catch (Exception $e) {
   Database::rollBack();
   echo 'ERROR!';
}

This is the databass class i am using:
http://pastebin.com/PfsiYysX

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:54:55+00:00Added an answer on June 17, 2026 at 7:54 am

    As Martin suggests, some javascript will prevent accidental pressing of both buttons. However it doesn’t work in all cases and certainly provides no protection against deliberate submisson of both forms. However it will prevent most users from arriving at the point where you apply real, effective controls to the operation.

    A more secure solution would be to incorporate a single use CSRF token (copy of the same token in both forms) – check and expire the token on the first request. The problem with this is that users may perceive that there is a fault if they split the session (open new window). There are ways of mitigating this – but it depends on the specific details of how the application is implemented.

    A better solution would be to model the as a finite state machine, allowing both updates when the data is in the initial state but disallowing a subsequent update. I’d have provided an example but that’s not possible from the data you have provided. So instead consider this: a user has filled a shopping basket and goes to the checkout. At this point they have 2 choices – make the purchase or discard the basket. If they click on ‘make purchase’, if so, then you set the status to ‘buying’ where the basket status is ‘at checkout’ if this is successful then you proceed with the purchase processing. If they click on ‘discard’ then you change the basket status to ‘discarding’ where the status is ‘at checkout’, if successful, then you proceed with the clean up. If either operation is not successful, then you report an error. Note that each operation should auto-commit – and this does not use locks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created one database and one table user in that while running my
I have simple database - one table with 6 collumns. 3 of them i
I have one database table which contains 8 columns. One of the columns is
I have one database table TABLE_TIPS with two value 1. tips_id (auto increment) 2.
I have loaded my database with one table under Data Connections in the Server
I have a database with many tables and one particular table has columns: name
I have a ms access database that has one table for each photo album
I have a database in SQL Server 2008 and one particular table has information
I have made a dump of my database in which one table is pretty
I have to copy a bunch of data from one database table into another.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.