Forum Moderators: coopster

Message Too Old, No Replies

Handling of Error Messages, and Application Structure in General

Searching for a comprehensive example or tutorial.

         

itKiwi

10:12 am on Feb 19, 2009 (gmt 0)

10+ Year Member



I am writing a conventional (not too simple, but not overly complex) PHP-MySQL address book /contact manager application. The various forms are processed by their own PHP file. How do I display success or failure messages which are generated in the form handler? I would like them to appear in a particular position, say in a "message" div under the form, above the footer, in my nice HTML forms. At the moment they are seen on a white screen "created" by the form handler. Bad.

I have searched the 'net for an example/tutorial showing me how to stucture my application, with the above problem as a typical issue. Can anyone point me to a "comprehensive" (but not too complex) example or tutorial which I can study and follow as a model ?

Another "decision" which would also be covered in a "structure" example or tutorial, is whether to open the database connection when I open the application, or to open and close it only when processing data. In the examples I have found, I have seen both systems used. Are there different applications for each system ?
Thanks for all help offered.

Sekka

5:17 pm on Feb 19, 2009 (gmt 0)

10+ Year Member



I think I get what you are saying. You essentially need something often referred to as "Flash" messages/alerts. They are messages you want to display in the next page as it were.

The way most people do this is to,

1) Store the message you want to display in the SESSION
2) Redirect the user to the next page
3) Get the message from the session, display it, and wipe the session of the message

As for DB connections, I only create a connection when one is needed. I use MySQLi and store my connection instance in one global place (using a Singleton is know of them). When I request the connection, one is created if it doesn't exist, otherwise it just returns the active connection.