Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with updating data

Status
Not open for further replies.

omoo

Programmer
May 30, 2005
87
US
I have the following script which insert the data after the user choose yes or no. But when I click on no, the script still insert the data. I could not find out the reason why. Anyone can help?

Code:
<%
DIM NAME, YEAR, RATING

NAME = Request.Form("NAME")
YEAR = Request.Form("YEAR")
RATING = Request.Form("RATING")

sqlcheck="select * from subdb_subcon_rating WHERE NAME LIKE '"&NAME&"' AND YEAR LIKE '"&YEAR&"'"
Set check = OraDatabase.Execute(sqlcheck)

if check.EOF then

	sql="INSERT into subdb_subcon_rating(NAME, YEAR, RATING) values ('"&NAME&"','"&YEAR&"','"&RATING&"')"
	Set objRS = OraDatabase.Execute(sql)	
%>
	<script language="VBScript">	
	MsgBox "Records have been inserted",64,"Alert"
	window.location= "input_records.asp"
	</script>
<%
else
%>
	<script language="VBScript">	
	
	returnvalue=MsgBox ("Records already exist in Database!"& vbCrLf &"Do you want to overwrite the records?",36,"Alert")
	If returnvalue=6 Then
<%
		OraDatabase.Execute("UPDATE subdb_subcon_rating SET RATING = '"&RATING&"' WHERE NAME LIKE '"&NAME&"' AND YEAR LIKE '"&YEAR&"'")
%>		
		MsgBox "Records have been inserted",64,"Alert"
		window.location="input_records.asp"
	end if
	if returnvalue=7 then
		MsgBox "Records NOT inserted",64,"Alert"
		history.go(-1)
	End If
	
	</script>

<%
end if
%>
 
This looks like confusion between client-side code and server-side code.

Remember that the server-side code executes before the client-side code.
 
Which are the server side code and client side code?
 
<script language="VBScript"> is a client side script.


QatQat

Life is what happens when you are making other plans.
 
Any ideas how to solve this issue?
 
I do not usually use any msgbox in my code, do it all server side,

example
Code:
if check.EOF then

    sql="INSERT into subdb_subcon_rating(NAME, YEAR, RATING) values ('"&NAME&"','"&YEAR&"','"&RATING&"')"
    Set objRS = OraDatabase.Execute(sql)    

response.write("records inserted <a href=input_records.asp>Click Here</a>")




else
response.write("the record already exists in the database")

end if
obviously this will look scrappy but should point you in the right direction

QatQat



Life is what happens when you are making other plans.
 
I need to use the Msgbox function. I am not sure if this function can still be retained.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top