Something to avoid conflict while saving to database - php

So I'm planning to create a code that will save in my database. (I have no problem in saving to my database thou.)
But I'm having a bit problem. The problem is to avoid having the same seat information displayed for the specific customer.
Something like this? (Sorry for the sample data that I will be doing.) The case is both are doing their inputs for their reservation at the same time.
[X] = taken data, [0] = blank data, [R] = customer data
1st viewing customer (having 2 data to be stored)
[X][X][X][R][R]
[0][0][0][0][0]
[0][0][0][0][0]
2nd viewing customer (having 1 data to be stored, and must be showed for this customer)
[X][X][X][X][X]
[R][0][0][0][0]
[0][0][0][0][0]
What the 2nd viewing customer actually sees. Which the customer mustn't encounter. And so on if there are other more customers are doing their inputs.
[X][X][X][R][0]
[0][0][0][0][0]
[0][0][0][0][0]
My first tactical plan is to create two database tables, one database table will serve as a dummy and the other will serve as the main database table. The logic is the dummy table will always update if there are customers making their inputs (which will have a problem by the time the customer closes the browser or didn't finish the transaction, the data stored at the dummy will still remain even after other customer accessed it again - which must not happen). And the main table will only update when the customer completed the whole transaction.
I know from the way I typed it is a bit confusing. But I really need some help in creating a logic to avoid this conflict the customer will see in my program. Or some tips if this kind of plan will not work. Like giving a note that (same sample above with 1st and 2nd customer) "This data is just a sample and sometimes will not be followed or the same with the e-mail sent to your registered e-mail addressed from this website."
Thank you in advance for your responses.

Well I don't think it's a good idea to save all clicks in final seat info table. Instead of that you can make something like temporary_seats base which will keep temporary information about reserved seats. In this table you would include information about seats that customers wishes to reserve.
Then you need to create javascript code querying API and getting all reserved (from destination table) and temporary reserved (from tmp table) and mark those seats free/occupied. You can do it constantly or check seat availability only when t

Related

How to store users transactions history on database and how to show the transaction history whenever a user wants to view their transactions

I’ve a problem that I don’t seem to find on the internet. I was trying to create a website where users transaction histories are saved on the database. Let’s say after a new user signs up and login and then starts to buy or sell stuff from the site, their past transactions should be saved in the database, so whenever they want to view their transaction it will show them their transactions histories. If they have 1, 3 , 12 or more transactions history it will show them everything. My problem now is I don’t know how to do it or even start. It should be able to look a table for each user.
Please make one more table with required transaction columns with post-fix of tablename_history. Use primary key with Auto increment for reference. i.e history_id.
But important thing is that you need to make separate transaction to Insert and Update Query to avoid performance issue.

How to solve this, 2 people working on same form

I've built a page with POST method form.
The form has a list of orders and tracking number for each order.
On this page two people are working at the same time, updating tracking numbers for order.
Example: when person 1 is updating the form with tracking number for order #126792 and click Submit, the database will be update tracking number for order #126792 and leave empty field for order #127299
At the same time person 2 is updating tracking number for order #127299, the database will update tracking number for order #127299 BUT insert empty tracking number for order #126792
You can see the form below in attached image, how can this situation be solved ?
Thank you.
Your question is too broad since it really depends on how your system and your users behave. Also, without you providing any code, I can't really answer with code.
However, I can provide a kind of decision alghorithm that might help you...
Questions:
Can the same record be updated by 2 different users at the same time?
No: Proceed to 2
Yes: Solution C, D or E
Can a user update 2 orders at the same time?
No: Solution A
Yes: Proceed to 3
Are empty values meaningful? (that is, can a user update/delete a record by submitting an empty "tracking code"?)
No: Solution B
Yes: Solution C, D or E
Solutions:
A. Change the frontend so that the user can only update 1 order BOX at a time
B. Ignore empty/false/null values in the backend.
C. Lock the records being edited:
User selects the records to update and informs the backend
The backend locks the records being updated until the user updates it or the "update time" expires
D. Use a version system: make each update a new version of the records and if a conflict arises, ask the last user that tried to update to resolve before committing the data.
E. Make the records "real time" (with short polling or long polling)
NOTE: Keep in mind that this assumes users are "smart", that is, they only behave in a predictable way (that you can specify without code) and they will oblige and won't try funny stuff.

Approving information prior to storing in database?

I am developing a web-based iPhone app and possibly a PC friendly website version as well. The goal here to to allow users to submit a form where specific input values would be stored into a table in the database.
Mind you this information is being gathered for public display and will be posted onto a calendar or list.
However, to prevent from any trolling or spamming, I'd like to make it where submissions have to be approved prior to being submitted into the table.
I have no problem with creating the table, connecting to the database, storing input values into the corresponding table columns. The only issue is how would I go about setting up an approval system? Can I add information to a table via email? Is there a way to approve admissions in cPanel?
This is something that I would like make as smooth as possible, I am expecting a lot of submissions daily with quite a bit of information.
You can have two approaches for this.
Approach 1
Have two copies of the table (which you want to save information
into). The first one should be named tableName_Input. The second one
should be tableName_Final.
Any Data in '_input' is considered raw and needs approval. Once approved the data will be moved into '_final'. The LIVE list/calendar always read from '_final' data.
Approach 2
Have a column named 'isApproved' with a flag 0/1. If 1 it is approved, else it is not. Only show data that is Approved.
Now, how do you get the data approved ?
You have a hard fast rule like spam filter that tells certain post is valid and approved by default
After every post, you send the user an email or some notification (unique to the user - post) that when answered back, shall mark it as approved.
Optional: You can place a column called as 'approval comments' to fill in something at the time of approval.
Flow chart
Tables
'FirstSubmitContent' - Table to store user submitted information
prior to approval.
'FinalSubmitContent' - Table that stores the final information
Code Pages
Content Page --> Contains the form the user fills the content
ContentActionPage --> Calls the controller --> calls the Model
Controller --> calls the model based on page action
Model --> Interacts with the Database table
I do not have any tools at my disposable now to write more detailed Code or Flowchart. I hope this puts in the right direction.
Validate the form on submission and save info in a temporary table in your DB with a randomly assigned activation code (you could use sha1). Then send an email to user with activation code and a link to verify it, ie. domain.com/activate.php?code=abcde12345.
The activation page can be very simple with just a $_GET['code']. Then check if you find a match in the DB for that code and finally prepare your query with all the info you gathered before to store it permanently.
Then you can make a cron job to delete all records from that table every 24-48 hours so users will have to activate within that time range.

where to keep temporary data?

I'm doing a system with Codeigniter , this is my first system with CI, and i'm also novice to PHP too.
I'm doing this for a hospital, in this i have the following problem
junior doctor first check the 1st visit patients and then if he can't handle them he refer them to the senior doctor
from registration room some patients are send to the eye checking room to check their eyes and then they go to the junior doctor
like wise i have temporary data to be kept on the system, references from one room to another and so on...
i need to get this details to the main GUI of the each person; for example in the Senior doctors UI there will be a tab named 1St time patients, in that the patients that was referred by the junior doctor will be shown to him! so i need to refer to the patients that was sent to senior doctor from the junior doctor and show them in the senior doctor's UI.
so my problem is how can i keep this temporary data to be referenced by the system? keeping them in the tables is not appropriate as i think because at the end of the day these data is not stored any where, only the patient table and few other tables will be keeping the data.
guys how can i achieve this kind of thing? any method of achieving this? technology that is easier to master that will allow me to keep temporary data?please give me some references or help by code to over come this problem.
regards,
Rangana
If the data is truly temporary, and has to be used by only one user at a time you need to stick it in session.
An entry level tuorial is here:
http://www.w3schools.com/PHP/php_sessions.asp
However if data is accessed by different users, but is simply not needed on following days, or you are storing a significant amount of data, you should probably keep it in the DB.
The DB should be able to store lots of data, so on a smallish app there is not much reason to keep clearing it out, but you could also include a housekeeping function that clears data that is old or irrelevant.
However when working with medical data, it may be a good idea to hang on to everything.
everything will do with ajax (or something that always refresh the browser for number of time like meta refresh tag) that will notify senior / junior doctor if any patient referred to them.
you need to add a flag at database if the doctor already retrieve the notification so it will not notify the doctor twice.
for example your database table :
Name of patient | referral | referrer | flag_retrieved
you need to specify referral doctor at the session so it can retrieve the correct record and then notify the doctor
then your system should :
request to database if any doctor to
refer patient to them over time (you can use ajax or meta tag)
database will check if any record match and not yet retrieved
send request to browser, than notify the doctor if any referred patient.
if you need to clean up the database, you can use cron every end of day for deleting any record at the table.

Possible to Dynamic Form Generation Using PHP global variables

Apparently there was confusion as to my original post so let me start over:
I am essentially creating an online shopping cart which gives a manager the ability to enroll his/her employees for training services which we provide. We charge $49 for the services for every employee enrolled. The primary difference between this and a traditional shopping cart however is that we must collect a solid amount of data about 'each' employee enrolled in the program - and this information is provided by the employer at the time of registration/purchase.
As a manager, I enter my personal information and then select how many employees I want to enroll. I currently have the site set up to handle 7 employees but actually need it to handle up to ~30. The issue I am having is the lack of dynamic ability and huge file sizes (especially in on the validation) I am running into.
Each fighter's information is passed and stored in session super globals such as: $_SESSION['F1Firstname']; and $_SESSION['F1SSN3']; and so on. I dont want to use javascript (and won't) to 'add another Enrollee' button because this can be turned off easily on the client side.
My assumptions are this:
1) I must be able to dynamically add variables to each new fighter so they may be stored in an online database and then passed along to our testing center - for example, emplotyee 1's name is F1FirstName; employee 12's Date of Birth is F12DOB1 and so on.
2) The validation for each employee will be the same based on each individual field (all first names must pass the same test). The validation for all email address must past the same email validation test and so on. If I simply build this by each individual record the validation file will be very large. I am thinking I need to add a Firstname array somehow but I'm not entirely sure.
3) I need this to be scalable that in the sense, I want a manager to enroll up to 100 employees, he/she can.
4) As I mentioned, this is like a shopping cart so a manager is enrolling all employees at once so they can pay for ALL of their employees in a single transaction.
Anybody got any ideas?
You can generate additional fields as needed by javascript. just provide a button 'add boxer' and there wouldn't have to be a lot of hidden fields.
If you're a "fairly new programmer" the best way would probably be to just have a form to input 1 fighter at a time. Not to mention this would be a lot more user friendly.

Categories