php mysql how to execute the commit() from a php file called from another file

I have a php script that processes database  mysql integration and will know if the queries fail and can handle those in the php script where the dbase queries are located. However, users of the application (when no mysql errors occur) will submit the page to continue to another function of the application which is on another page. On the new called page there may be errors related to another part of the application and if these occur the information written to the dbase in the previous calling page will need to be rolled back as they are no longer accurate and leaving them in the dbase will create a dbase integrity problem that will cause many errors in a dynamically updated web site. I need to call the commit() after getting to the new called page after verifying that there are no errors in the 2nd phase of the application which is in the called page. I cannot get commit() to work in the called page. Calling it in the previous page is not an option as this makes it impossible for the rollback to occur after commit() has been executed.

The dbase table are  mysql InnoB
as always Im in a hurry, thanks for any help
Thanks
Ron McCainAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

enkorCommented:
make your own function like "function myFnc(){Commit();}" in the 2nd php file and include this php file onti the 1st one. You will be able to call myFnc() which will contain Commit()
0
MarsMCommented:
An alternative could be to store the information in the session and do all the queries when the user has finished.
0
Ron McCainAuthor Commented:
cant use that one MarsM: because of the need to parse alot of information that has to be resolved in the first page and accepted as ok before the second page is called, I cant write it to the dbase here though because of many issues that have to be checked in the second page, I tried this already, thanks for the help though

enkor:, I tried something like this and could not get it to work this is the reason for the question here in EE, I placed the transaction functions in an include file and included in into the 2nd file and tried to call the functions  but it didnt work. Are you saying create the transaction functions in the 2nd file and include the entire 2nd file into the first?? if so I dont catch the reasoning there.
If so I already have the functions in the 1st file and the 1st file has session enabled. just cant get either way to work. Sounds like this is where I need to go though, can you elaborate just a bit on what you mean please.
thanks

0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Ron McCainAuthor Commented:
by the way, thanks to all for respondin its 3:50 am where I am and Im on a deadline crunch,
0
Ray PaseurCommented:
Without knowing a lot more about your data base and application we may be shooting in the dark, but here is something I would at least discuss...

In page one, start the session and get a unique ID (maybe something like PHPSESSID).  Use this ID as the name for a "temporary" data base table.  As the data is validated, write it into the table.  Then on page 2, start the session again, grab the information from the "temporary" table (not a MySQL TEMPORARY TABLE, just the one that you have created locally with the intent that it be temporary).

Once you have validated all of the page 2 information, you are ready to begin the transaction.  Copy the page 1 information into the "real" DB.  Then copy the page 2 information into the "real" DB.  Then commit.

You may want to write a garbage collector that is started every time page 1 is loaded.  It would look for your "temporary" tables older than a specific lifetime and delete them before it presented anything to the client.
0
Ron McCainAuthor Commented:
thanks again for the responses, I may have a simple solution if someone can verify. When the user submits one of the forms on the 1st page to accept the outcome to form ID is evidence of success in ths case. If I can check that specific form submit from the 1st page in the script on the 2nd page then I may be able to run the commit() at that point. I have found that the function I have on the 2nd page is not being triggered because the isset($_POST[form1]) test is not working (i.e we are skipping the commit() function). Should I set a session variable in the 1st page for the form in order to catch it on the 2nd page?
0
Ray PaseurCommented:
Short answer: Yes.
0
Ron McCainAuthor Commented:
thanks, a bit more would be helpful but I will give it a try
0
Ray PaseurCommented:
Slightly longer answer: You might be able to do something like this...

Page 1:
session_start();
$_SESSION["page_1_POST"] = $_POST;
/* VALIDATE PAGE ONE DATA */
$_SESSION["page_1_OK"] = TRUE; // SET AFTER SUCCESSFUL VALIDATION

Page 2:
session_start();
/* VALIDATE PAGE TWO DATA */
if ($_SESSION["page_1_OK"] == TRUE)
{
   /* PROCESS PAGE ONE DATA USING $_SESSION[["page_1_POST"] */
   /* PROCESS PAGE TWO DATA */
    commit...

But let's step back from the question a little bit.  There are lots of ways to handle data validation, and even partial data base updates.  But you should never have a data base design that can break itself if data from two separate requests gets "out of sync."  That's why I would consider using the pseudo-temporary tables to get all of the data together into one place.  Once you know it is good, then LOCK TABLES on the main DB and update, or start the transaction, then commit, or whatever strategy works best to get the final updates completed.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ron McCainAuthor Commented:
Thanks Ray, Perfect!!! and I agree 110% on the database methology, I assure you that this will be done, I needed to get a phase of the project into beta to allow testing on another branch hence the urgency (also my brain is toast as I am on about 23 hours without sleep) however,  before we put anything into production we will take appropriate measure for dbase integrity. I truly appreciate yur kind assistance and very valuable advice.
Thanks Much
0
Ron McCainAuthor Commented:
excellent assistance, attitude and knowledge, got to the point with exactly what we need to know.
0
Ray PaseurCommented:
Thanks for the points, good luck with it, and GET SOME SLEEP!  ;-)

Best regards, ~Ray
0
Ron McCainAuthor Commented:
thanks again Ray and will do on the sleep
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.