response.redirect (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


crosscreek -> response.redirect (3/11/2008 12:35:02)

I am able to add a new dog, but trying to redirect them to the pedigree page.

I've looked around & found a partial answer, but I just can't seem to get it to work or the pedigree page to reconize it.

I have the following code for update

If Not duplicate then
objrs.addnew
objrs("name") = strdoggy
objrs.update
NewID = objrs("ID")
Response.redirect "pedigree2.asp?id=" & objrs("newid") & ""
end if

I get the error
Item cannot be found in the collection corresponding to the requested name or ordinal.

or not reconized clng

My SQL for the pedigree2 page ends with

WHERE tblDOG.ID="& clng(Request.querystring("ID"))

Any input? Thanks this forum has been helpful





rdouglass -> RE: response.redirect (3/11/2008 14:24:23)

How 'bout this:

...
NewID = objrs("ID")
Response.redirect "pedigree2.asp?id=" & NewID
end if
...

That any better?




crosscreek -> RE: response.redirect (3/11/2008 16:10:13)

Thanks for the quick reply...(and the response to my other question...Quotes are a pain at times)

the above kinda worked.

I received the following error.

Type mismatch: 'clng'

This must be a refrence to the SQL in the pedigree page.

WHERE tblDOG.ID="& clng(Request.querystring("ID"))

Spooky suggested the clng because I wanted people to be able to change the ID in the url to bring up the pedigree they want. (this way they can refrence the pedigree from somewhere else)

I'm getting closer....

I used this
Response.redirect "pedigree2.asp?id=" & clng(newid)

I was directed to the pedigree page put it was ID=0 (which is not the id of the new dog)





Spooky -> RE: response.redirect (3/11/2008 18:14:47)

Just use this?
Response.redirect "pedigree2.asp?id=" & newid

On the pedigree2 page, its there youll want to use clng - but only if the ID will always be numeric





crosscreek -> RE: response.redirect (3/11/2008 18:46:45)

quote:

Response.redirect "pedigree2.asp?id=" & newid


Gives me

Type mismatch: 'clng'
/pedigree2.asp, line 21

The id is always numeric

I can get it to either show pedigree page with ID=0 or mismatch statement.

This is the full adddog.asp code
Dim dublicate, strdoggy, objrs
strdoggy=trim(request.form("doggy"))
If Request.form("doggy") = "" OR Request.form("doggy") = " " Then
	Response.Write ("No Search Text Entered! YOu must type a name.")
	Response.Write ("<a href='adddog.htm'> Click to go back to the Add dog Page page")
Else
duplicate=false
Set objrs = Server.CreateObject("ADODB.Recordset") 
objRS.open "tbldog", myConn, , adlockoptimistic, adcmdtable
Do while not (objrs.eof OR duplicate)
	If (strcomp(objrs("name"), strdoggy, vbTextCompare) = 0) then
	duplicate=True
	Response.write "This dog has already been entered. Please go back to enter a new dog in or click below to go to the pedigree page."
	duplicate=true
End if
objrs.movenext
loop
If Not duplicate then
objrs.addnew
objrs("name") = strdoggy
objrs.update
NewID = objrs("ID")
Response.redirect "pedigree2.asp?id="& newid
end if

objrs.close
set objrs = nothing
end if
myConn.close
Set myConn = nothing








Spooky -> RE: response.redirect (3/11/2008 19:22:58)

In the URL after entering a new dog (eg pedigree2.asp?id=??), what does the URL text show when the page errors?
What is the code for pedigree2.asp?




crosscreek -> RE: response.redirect (3/11/2008 21:14:41)

url: http://www.ravenswayhrc.com/pedigree2.asp?ID=
(there's nothing after...the otherway would get ID=0)
Error:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'clng'
/pedigree2.asp, line 21

Line 21 is the SQL

Below is most of the pedigree2 page. Code is all there, I just took out some of the "look" of the page, that really not relavent to what's going on.

I wonder if it's because it doesn't know which ID to choose because of the pedigree sql.

<%
'this is the dog info query

Dim strSQL
strSQL = "SELECT tblDOG.ID AS ID, tblDOG.NAME AS NAME, "_
& " tblDOG.PreTi, tblDOG.SuffTi, tblDOG.callname, tblDOG.DOB, tblGEN.Gender as Gender, " _
& " tblColor.Color, tblDOG.Owner, tblDOG.Breeder, tblDOG.DOD, tblDOG.website, tblDOG.Hips, " _
& " tblDOG.Eyes, tblDOG.elbow, tblDOG.CNM, tblDOG.UKC, tblDOG.AKC, dam.ID AS damid, sire.ID AS sireid, " _
& " Ssire.id AS ssireid, Sdam.ID AS sdamid, Dsire.ID as dsireid, Ddam.ID AS Ddamid, SSsire.ID AS sssireid, " _
& "SSdam.ID AS ssdamid, SDsire.ID AS sdsireid, SDdam.ID AS sddamid, DSsire.ID AS dssireid, DSdam.ID AS dsdamid, " _
& " DDsire.ID AS ddsireid, DDdam.ID as dddamid, CONCAT_WS(' ', tbldog.PreTi, tbldog.NAME, tbldog.suffti) AS Fullname, " _
& " CONCAT_WS(' ', sire.PreTi, sire.NAME, sire.suffti, '(',scolor.color,')') AS sirefull, " _
& " CONCAT_WS(' ', dam.PreTi, dam.NAME, dam.suffti, '(',dcolor.color,')') AS damfull, CONCAT_WS(' ', ssire.PreTi, ssire.NAME, ssire.suffti, '(',SScolor.color,')') AS Ssfull, CONCAT_WS(' ', Sdam.PreTi, Sdam.NAME, Sdam.suffti, '(',SDcolor.color,')') AS Sdfull, CONCAT_WS(' ', Dsire.PreTi, Dsire.NAME, Dsire.suffti, '(',DScolor.color,')') AS DSfull, CONCAT_WS(' ', Ddam.PreTi, Ddam.NAME, Ddam.suffti, '(',DDcolor.color,')') AS DDfull, CONCAT_WS(' ', SSsire.PreTi, SSsire.NAME, SSsire.suffti, '(',SSScolor.color,')') AS SSSfull, CONCAT_WS(' ', SSdam.PreTi, SSdam.NAME, SSdam.suffti, '(',SSDcolor.color,')') AS SSDfull, CONCAT_WS(' ', SDsire.PreTi, SDsire.NAME, SDsire.suffti, '(',SDScolor.color,')') AS SDSfull, CONCAT_WS(' ', SDdam.PreTi, SDdam.NAME, SDdam.suffti, '(',SDDcolor.color,')') AS SDDfull, CONCAT_WS(' ', DSsire.PreTi, DSsire.NAME, DSsire.suffti, '(',DSScolor.color,')') AS DSSfull, CONCAT_WS(' ', Dsdam.PreTi, Dsdam.NAME, Dsdam.suffti, '(',DsDcolor.color,')') AS DsDfull, CONCAT_WS(' ', Ddsire.PreTi, Ddsire.NAME, Ddsire.suffti, '(',Ddscolor.color,')') AS Ddsfull, CONCAT_WS(' ', DDdam.PreTi, DDdam.NAME, DDdam.suffti, '(',DDDcolor.color,')') AS DDDfull FROM ((((((((((((((((((((((((((((tblGEN RIGHT JOIN (tblColor RIGHT JOIN tblDOG ON tblColor.ColorID = tblDOG.ColorID) ON tblGEN.GenID = tblDOG.genID) LEFT JOIN tblDOG AS sire ON tblDOG.sireID = sire.ID) LEFT JOIN tblDOG AS dam ON tblDOG.damID = dam.ID) LEFT JOIN tblDOG AS Ssire ON sire.sireID = Ssire.ID) LEFT JOIN tblDOG AS Sdam ON sire.damID = Sdam.ID) LEFT JOIN tblDOG AS Dsire ON dam.sireID = Dsire.ID) LEFT JOIN tblDOG AS Ddam ON dam.damID = Ddam.ID) LEFT JOIN tblDOG AS SSsire ON Ssire.sireID = SSsire.ID) LEFT JOIN tblDOG AS SSdam ON Ssire.damID = SSdam.ID) LEFT JOIN tblDOG AS SDsire ON Sdam.sireID = SDsire.ID) LEFT JOIN tblDOG AS SDdam ON Sdam.damID = SDdam.ID) LEFT JOIN tblDOG AS DSsire ON Dsire.sireID = DSsire.ID) LEFT JOIN tblDOG AS DSdam ON Dsire.damID = DSdam.ID) LEFT JOIN tblDOG AS DDsire ON Ddam.sireID = DDsire.ID) LEFT JOIN tblDOG AS DDdam ON Ddam.damID = DDdam.ID) LEFT JOIN tblColor AS Scolor ON sire.ColorID = Scolor.ColorID) LEFT JOIN tblColor AS Dcolor ON dam.ColorID = Dcolor.ColorID) LEFT JOIN tblColor AS SScolor ON Ssire.ColorID = SScolor.ColorID) LEFT JOIN tblColor AS SDcolor ON Sdam.ColorID = SDcolor.ColorID) LEFT JOIN tblColor AS DScolor ON Dsire.ColorID = DScolor.ColorID) LEFT JOIN tblColor AS DDcolor ON Ddam.ColorID = DDcolor.ColorID) LEFT JOIN tblColor AS SSScolor ON SSsire.ColorID = SSScolor.ColorID) LEFT JOIN tblColor AS SSDcolor ON SSdam.ColorID = SSDcolor.ColorID) LEFT JOIN tblColor AS SDScolor ON SDsire.ColorID = SDScolor.ColorID) LEFT JOIN tblColor AS SDDcolor ON SDdam.ColorID = SDDcolor.ColorID) LEFT JOIN tblColor AS DSScolor ON DSsire.ColorID = DSScolor.ColorID) LEFT JOIN tblColor AS DSDcolor ON DSdam.ColorID = DSDcolor.ColorID) LEFT JOIN tblColor AS DDScolor ON DDsire.ColorID = DDScolor.ColorID) LEFT JOIN tblColor AS DDDcolor ON DDdam.ColorID = DDDcolor.ColorID WHERE tblDOG.ID="& clng(Request.querystring("ID"))

Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.open strSQL, myConn, , adlockreadonly
%>
<strong><font size=5><%
Do While Not objRS.EOF
Response.Write objRS("fullname")
%></font></strong>
<br><br><br><br>

<table width="250">
<tr><td>CALLNAME: </td><td>"<%=objrs("callname")%>"</td>
<tr><td>GENDER:</td><td><%=objrs("gender")%></td>
<tr><td>Color:</td><td><%=objrs("color")%></td>
<tr><td>Date of Birth:</td><td><%=objrs("dob")%></td>
<tr><td>Date of Death:</td><td><%=objrs("dod")%></td>

</table>

<br><strong><font size=5>Pedigree:</font></strong>
<p> </p><table width="100%" height="100">
<tr><td width="163" rowspan="2"><font size="2"><%=objRS("fullname")%></font></td><td width="273"><font size="2"><%="<a href=""pedigree.asp?id="&objRS("sireid")&""">"&objRS("sirefull")&"</a>"%></font></td>
<td>
<%
objRS.Movenext
Loop

objRS.Close
Set objRS = Nothing

myConn.Close
Set myConn = Nothing
%>




William Lee -> RE: response.redirect (3/11/2008 21:34:15)


quote:

ORIGINAL: crosscreek

quote:

Response.redirect "pedigree2.asp?id=" & newid


Gives me

Type mismatch: 'clng'
/pedigree2.asp, line 21



If you attempt to clng an empty string, you'll get this error. Check to see that newid has a value. Response.write the value of newid just before the redirecting.

Also, I spotted that you have declared dublicate where you actually meant duplicate
Try also to maintain case sensitivity eg NewID , newid. Keep them consistent.
Correct this and see if you get better results.






crosscreek -> RE: response.redirect (3/12/2008 14:57:20)

Thanks for the response

I fixed what you said & response.write the id (my hosting company's server when down or something for a while & just got my web page up again)

If Not duplicate then
objrs.addnew
objrs("name") = strdoggy
objrs.update
NewID = objrs("ID")
Response.write objrs("NewID")
end if

I received the following error....basically it's not find the "new" id number.

ADODB.Recordset error '800a0cc1'
Item cannot be found in the collection corresponding to the requested name or ordinal.





Spooky -> RE: response.redirect (3/12/2008 15:05:25)

Does the field "name" and "id" exist in the database?

The main problem will be Response.write objrs("NewID")
It should be Response.write ("NewID")




crosscreek -> RE: response.redirect (3/12/2008 15:11:39)

Name & ID are the field names. I've checked mysql & the names I been entering in are being added.

The first time I did response.write ("NewID")

It came back

NewID






crosscreek -> RE: response.redirect (3/12/2008 15:42:35)

OK i double check the database & the names are not being added. There were being added yesterday. So now it's an addition problem again.
[:'(][:@]
They are being added....I just didn't go to the next page

I'll try what you responed below




Spooky -> RE: response.redirect (3/12/2008 15:44:36)

Ooops -:

response.write NewID




crosscreek -> RE: response.redirect (3/12/2008 15:53:48)

I received a Blank page. Nothing there.

So it's not "reading" the new id number. The names are being added, & even it if put in a duplicate name I am getting my error dog already entered error. My database is Mysql & not sure if there a code that I have to use to retrieve the new id number

Thanks for your help








Spooky -> RE: response.redirect (3/12/2008 16:55:18)

Im not sure if you can do that via mySQL, normally I would do it this way (after the insert) :

Set objRS2 = myConn.Execute("SELECT ID FROM tbldog WHERE ID = LAST_INSERT_ID()")
NewID = objRS(0)
objRS2.close 




crosscreek -> RE: response.redirect (3/12/2008 17:46:30)

Spooky,

If I am understanding your correctly do I need to create a SQL with an INSERT in place of the objrs.addnew comand?




Spooky -> RE: response.redirect (3/12/2008 17:48:33)

That would be my preference, but this code could possibly work placing it after the exisiting code




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.078125