Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: double entries in database after refresh


Message #1 by "kostas lagos" <nkia@i...> on Thu, 21 Nov 2002 15:28:57
Hello everyone

I have some problems with one of my asp pages..

Im posting the values from a form to a database table called quest_data

In the same form i have a list box which displays some records from the 
database(quest_data) that fulfil some conditions as written below:

sqlStr="SELECT a.YEAR_EXP yearExp, a.USED_REC usedRec, a.MORE_INV moreInv, 
a.GAIN_KNOW gainKnow "
sqlStr=sqlStr & ", RPAD(b.descr,106,'&nbsp;') stringDescr, RPAD
(c.description, 86, '&nbsp;') descrParam1, "
sqlStr=sqlStr & "RPAD(d.description, 85, '&nbsp;') descrParam2,RPAD
(e.description,92, '&nbsp;') descrParam3, "
sqlStr=sqlStr & "f.description descrParam4"
sqlStr=sqlStr & " FROM quest_data a, knowledge b,param1 c,param2 d,param3 
e,param4 f"
sqlStr=sqlStr & " WHERE a.KOD_YPAL=1111 AND b.id=a.knowledge AND 
c.id=a.YEAR_EXP AND " 
sqlStr=sqlStr & " d.id=a.USED_REC AND e.id=a.MORE_INV AND 
f.id=a.GAIN_KNOW"    

I also have an 'insert' statement which sends the posted data to the 
database table (quest_data)

The problem is that if someone posts the data (via a submit button)
and after that refreshes the page i get two same entries!

I dont know if the solution lies on error handling (which i dont think so)
or something else..

please if someone knows something pleeeease let me know 

Kostas Lagos
Message #2 by Mark Eckeard <meckeard2000@y...> on Thu, 21 Nov 2002 08:14:51 -0800 (PST)
One of two ways to prevent this:

1 - After the user submits the form and the insert(s)
were successfull, set a session variable or cookie
indicating this (ie, session("HasSubmitted") = true). 


At the top of the page that does the insert, check for
the value like this:

if session("HasSubmitted") then
  response.write ("you have already submitted")
else
  'Do code to submit
end if

2 - You can check the database for an exact match of
the record before you insert it.

I use both, just to be safe.

Mark.
--- kostas lagos <nkia@i...> wrote:
> Hello everyone
> 
> I have some problems with one of my asp pages..
> 
> Im posting the values from a form to a database
> table called quest_data
> 
> In the same form i have a list box which displays
> some records from the 
> database(quest_data) that fulfil some conditions as
> written below:
> 
> sqlStr="SELECT a.YEAR_EXP yearExp, a.USED_REC
> usedRec, a.MORE_INV moreInv, 
> a.GAIN_KNOW gainKnow "
> sqlStr=sqlStr & ", RPAD(b.descr,106,'&nbsp;')
> stringDescr, RPAD
> (c.description, 86, '&nbsp;') descrParam1, "
> sqlStr=sqlStr & "RPAD(d.description, 85, '&nbsp;')
> descrParam2,RPAD
> (e.description,92, '&nbsp;') descrParam3, "
> sqlStr=sqlStr & "f.description descrParam4"
> sqlStr=sqlStr & " FROM quest_data a, knowledge
> b,param1 c,param2 d,param3 
> e,param4 f"
> sqlStr=sqlStr & " WHERE a.KOD_YPAL=1111 AND
> b.id=a.knowledge AND 
> c.id=a.YEAR_EXP AND " 
> sqlStr=sqlStr & " d.id=a.USED_REC AND
> e.id=a.MORE_INV AND 
> f.id=a.GAIN_KNOW"    
> 
> I also have an 'insert' statement which sends the
> posted data to the 
> database table (quest_data)
> 
> The problem is that if someone posts the data (via a
> submit button)
> and after that refreshes the page i get two same
> entries!
> 
> I dont know if the solution lies on error handling
> (which i dont think so)
> or something else..
> 
> please if someone knows something pleeeease let me
> know 
> 
> Kostas Lagos


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus ? Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
Message #3 by "kostas lagos" <nkia@i...> on Fri, 22 Nov 2002 13:38:52
> One of two ways to prevent this:

1 - After the user submits the form and the insert(s)
were successfull, set a session variable or cookie
indicating this (ie, session("HasSubmitted") = true). 


At the top of the page that does the insert, check for
the value like this:

if session("HasSubmitted") then
  response.write ("you have already submitted")
else
  'Do code to submit
end if

2 - You can check the database for an exact match of
the record before you insert it.

I use both, just to be safe.

Mark.
--- kostas lagos <nkia@i...> wrote:
> Hello everyone
> 
> I have some problems with one of my asp pages..
> 
> Im posting the values from a form to a database
> table called quest_data
> 
> In the same form i have a list box which displays
> some records from the 
> database(quest_data) that fulfil some conditions as
> written below:
> 
> sqlStr="SELECT a.YEAR_EXP yearExp, a.USED_REC
> usedRec, a.MORE_INV moreInv, 
> a.GAIN_KNOW gainKnow "
> sqlStr=sqlStr & ", RPAD(b.descr,106,'&nbsp;')
> stringDescr, RPAD
> (c.description, 86, '&nbsp;') descrParam1, "
> sqlStr=sqlStr & "RPAD(d.description, 85, '&nbsp;')
> descrParam2,RPAD
> (e.description,92, '&nbsp;') descrParam3, "
> sqlStr=sqlStr & "f.description descrParam4"
> sqlStr=sqlStr & " FROM quest_data a, knowledge
> b,param1 c,param2 d,param3 
> e,param4 f"
> sqlStr=sqlStr & " WHERE a.KOD_YPAL=1111 AND
> b.id=a.knowledge AND 
> c.id=a.YEAR_EXP AND " 
> sqlStr=sqlStr & " d.id=a.USED_REC AND
> e.id=a.MORE_INV AND 
> f.id=a.GAIN_KNOW"    
> 
> I also have an 'insert' statement which sends the
> posted data to the 
> database table (quest_data)
> 
> The problem is that if someone posts the data (via a
> submit button)
> and after that refreshes the page i get two same
> entries!
> 
> I dont know if the solution lies on error handling
> (which i dont think so)
> or something else..
> 
> please if someone knows something pleeeease let me
> know 
> 
> Kostas Lagos


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus ? Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com



Thank you very much for the tip

My problem seem to be that i was trying to fit the all code in one page

Both ways are needed,as  mentioned, for security reasons (I also use both).

  Return to Index