Database issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nawhaley
Forum Commoner
Posts: 85
Joined: Wed May 18, 2005 11:43 am

Database issue

Post by nawhaley »

I've got a small issue that I wonder if theres a way to put failsafe in. When I go to edit a question in my SQL database using PhP and hit the back button while at the editing screen it erases the question entirely from the database meaning it blanks it out. Is there anyway to set it up so that if you do that it automatically resaves the orginal data back into the database?
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
Easiest way is not to save half-finished user input. Only update the database, if changes are complete.

djot
-
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Im not sure why the page is being executed again, because most browsers will display a cached version of the page.

One possible solution would be to use sessions. Once the database information has been inserted, set a session flag. Now, if they press the back button, check for that flags existance. If it exists, simply deny the update..

for example

Code: Select all

session_start();

if (isset($_SESSION["dbFlag"])) {
   echo "Information has already been updated";
}
else {
   $_SESSION["dbFlag"] = true;
   ..perform update
}
nawhaley
Forum Commoner
Posts: 85
Joined: Wed May 18, 2005 11:43 am

Post by nawhaley »

I was the same way Jcart it kind of confused me. I know it was accessing the datbase to pull up the old question that I wanted to change and then filling in the text field with it as well in case it was a small edit but I thought it would of closed the connection at that point. Apparently it just leaves it open and when you hit the back button on the browser it assumes you want to blank out everything its really odd. Perhaps it would be better to close the database link manually after I pull what I need from it instead of setting a session variable?
nawhaley
Forum Commoner
Posts: 85
Joined: Wed May 18, 2005 11:43 am

Post by nawhaley »

found it, apparently its better to manually close your connection once you've pulled the data you want to display out of the database. I was under the impression that odbc_connect automatically closed its connection once the data was done being pulled unlike doing odbc_pconnect which leaves a permenant connection. Guess this classifies as a rookie mistake :? .
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

using pconnect is not rookie, imo, I use it all the time. Although it does depend on the situation, because I have several parts of my application interacting with the database, so it makes sense to use a persistant connection sometimes..
nawhaley
Forum Commoner
Posts: 85
Joined: Wed May 18, 2005 11:43 am

Post by nawhaley »

no no no not talking about using pconnect. I was using just normal odbc_connect and wasn't doing an odbc_close() once I was done pulling data to display thats what was blanking out the data when I would hit the back button. If I do an odbc_close() once I have all the data I want out of the database I can use the back button without losing any data. I misunderstood how the odbc_connect function was working that was my rookie mistake :).
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Ah. Glad to hear your problem was solved.
Post Reply