Page 1 of 1
Database issue
Posted: Wed Jan 04, 2006 9:19 am
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?
Posted: Wed Jan 04, 2006 4:47 pm
by djot
-
Easiest way is not to save half-finished user input. Only update the database, if changes are complete.
djot
-
Posted: Wed Jan 04, 2006 4:48 pm
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
}
Posted: Thu Jan 05, 2006 10:44 am
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?
Posted: Thu Jan 05, 2006 11:02 am
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

.
Posted: Thu Jan 05, 2006 11:07 am
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..
Posted: Thu Jan 05, 2006 11:13 am
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

.
Posted: Thu Jan 05, 2006 11:30 am
by John Cartwright
Ah. Glad to hear your problem was solved.