One more Hill (Full Version)

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



Message


crosscreek -> One more Hill (3/14/2008 22:32:45)

My last page to work on is my parents.htm & parentsubmit.asp pages

I have created a form to edit the sire & dam of a dog. At this time I am working just on the sire.

I have a textbox in which someone types a new name of the sire & submits it to the parentsubmit.asp page.

My code for the parentsubmit.asp page works fine.

Blank make sireID field null.
Like shows dogs in database LIKE the dog in the request.form
Exact Match (will work on that once I figure out the like)

I have a hyperlink of the dogs that are LIKE

Below is the code for that.

If objrs("ranking") = 1 Then
Response.Write "this is what will show if a dog exact matches or it will update the field"
Else
Response.Write "There a few dogs that match. Please select a dog below. <BR>"
Do While Not objRS.EOF

%>
<a href="parentsubmit2.asp?id=<%=request.form("ID")%>&Sire=<%=Escape(objRS("name"))%>"><%=objRS("name")%></a><br>
<%
objRS.MoveNext
Loop
End If
objRS.Close
Set objRS = Nothing

My question is: How do I get the hyperlink to update database????

I am thinking that if someone clicks on the hyperlink it will refresh the parentsubmit page, so do I need to add another code that will handle when they click on the hyperlink? And this is how the database will be updated?

How do I split up the code so I it knows what to do when someone clicks on the hyperlink and can activate the update sql.

I eventually want to beable to add/edit dam as well after the sire is updated.





rdouglass -> RE: One more Hill (3/15/2008 11:11:50)

quote:

How do I split up the code so I it knows what to do when someone clicks on the hyperlink


I frequently ad an identifyer to hyperlinks to idenitfy them as in:

<a href="parentsubmit2.asp?id=<%=request.form("ID")%>&Sire=<%=Escape(objRS("name"))%>&item=sire"><%=objRS("name")%></a>

Then you can separate the different SQL like this:

<%If request.querystring("item") = "sire" Then
mySQL = (the sql to update the sire)
ELSE
mYSQL = (the normal SQL or whatever)
End iF%>

Or you could use CASE statements if you wanted to do it that way. My point is stick another parameter in the querystring so you can separate the different SQL activities that way. Like:

That help any?




crosscreek -> RE: One more Hill (3/15/2008 12:19:22)

It's very helpful thank you...the seperation of the &Item will help when I try to seperate everything.

I been working with the CASE statment & subroutines a little, because I think this will be easier to navigate through the page.

My goal is the have someone type in a name in each of the seperate sire & dam text boxes in the parents.asp page

From there list the dogs of the sire that matches (or give them the option to add the dog)

They click on the hyperlink of the sire that matches, then the page reloads update the sire and then goes to the dam information.

I can't seem to get the sub rountine to run the "Sub EditRecord (dogid)" part and retrieve the information I need or run the th initial code to show all the dogs that match (running the 1st step). I get a blank page...

I'm doing this step by step,


<%@ Language=VBScript %>
<% 'option explicit%>
<%
Const Action_Add = "add"
Const Action_View = "View"
Const Action_Edit = "edit"

%>

<%
'sub main holds main loop
Sub Main()
Dim strAction
'deterime the action that was selected
strAction = Request("action")


Dim dogid, bolmatch
If request.form("ID") <> " " then
bolmatch = True
dogid = (request.form("ID"))
Response.write "this worked, but need to send to editrecord sub"
End If
If NOT bolmatch then
Response.Write "error happened"
End If
Select Case strAction
Case Action_Edit
EditRecord dogid
Case Else
Response.Write "Error happend with case"
End Select
End Sub

Sub EditRecord (dogid)
Dim id, sires, dam, SireID, DamID, sSQL, SRSQL, SireSQL
ID=request.form("dogid")
SireID=request.form("sireID")
sires=request.form("sires")
DamID=request.form("damID")
dam=request.form("dam")
sSQL = "Update tbldog Set sireID = (0) WHERE ID= " & ID &""
Response.Write "DEBUG SQL: " & sSQL & "<HR>" ' remove when it works
SRSQL = "SELECT 1 as ranking, tblDOG.ID AS dogID, tblDOG.name AS name, tblDOG.sireID AS SireID, Sire.name AS Sires, Sire.ID AS IDSire " _
& " FROM tblDOG LEFT JOIN tblDOG AS Sire ON tblDOG.sireID = Sire.ID WHERE tbldog.name = '" & sires & "' " _
& " UNION " _
& "SELECT 2 AS ranking, tblDOG.ID AS ID, tblDOG.name AS name, tblDOG.sireID AS SireID, Sire.name AS Sires, Sire.ID AS IDSire " _
& " FROM tblDOG LEFT JOIN tblDOG AS Sire ON tblDOG.sireID = Sire.ID WHERE tbldog.name LIKE '%" & sires & "%' " _
& "ORDER BY ranking, Sires"
Response.Write "DEBUG SQL: " & SRSQL & "<HR>" ' remove when it works
SireSQL = "UPDATE tblDOG LEFT JOIN tblDOG AS sire ON tblDOG.sireID = Sire.ID SET tblDOG.sireID = () WHERE sire.name =" & name & ""
Response.Write "DEBUG SQL: " & SireSQL & "<HR>" ' remove when it works

Dim objRS
Set objRS = Server.CreateObject("ADODB.recordset")
objRS.Open sSQL, myConn, , adLockOptimistic

If Request.form("sires") = " " OR Request.form("sires") = "" THEN
set objrs = myconn.execute(sSQL)
Response.Write "DEBUG SQL: " & sSQL & "<HR>" ' remove when it works
End If

THERE'S MORE CODE BELOW, BUT DIDN'T REALLY SEE THE POINT OF POSTING IT.





rdouglass -> RE: One more Hill (3/15/2008 12:36:39)

quote:

THERE'S MORE CODE BELOW, BUT DIDN'T REALLY SEE THE POINT OF POSTING IT.


Is the next line just "End Sub" 'cause I don't see the end to that sub. It sometimes helps to see the big picture.

Also, is there by chance a URL where we could look?




crosscreek -> RE: One more Hill (3/15/2008 12:50:03)

Here's the full code for the page with the case statements. I changed it up just a bit to try some stuff, but still getting blank page.

<body>
<%@ Language=VBScript %>
<% 'option explicit%>
<%
Const Action_Add = "add"
Const Action_View = "View"
Const Action_Edit = "edit"
Const Valicate_Yes = "y"
%>

<!-- #include virtual="/adovbs.inc" -->
<!-- #include file="openconn.inc" -->
<%
'sub main holds main loop
Sub Main()
Dim strAction
'deterime the action that was selected
strAction = Request("action")

Dim ID, bolmatch
If request.form("ID") <> " " then
	bolmatch = True
ID = request.form("ID")
Response.write "this worked, but need to send to viewedit sub"
End If

If NOT bolmatch then
	Response.Write "error happened"
End If

 Select Case strAction
Case Action_Edit
	EditRecord ID
Case Else 
Response.Write "Error happend with case"
End Select
End Sub

Sub EditRecord (ID)
Dim sires, dam, SireID, DamID, sSQL, SRSQL, SireSQL
SireID=request.form("sireID")
sires=request.form("sires")
DamID=request.form("damID")
dam=request.form("dam")
sSQL = "Update tbldog Set sireID = (0) WHERE ID= " & ID &""
Response.Write "DEBUG SQL: " & sSQL & "<HR>" ' remove when it works
SRSQL = "SELECT 1 as ranking, tblDOG.ID AS dogID, tblDOG.name AS name, tblDOG.sireID AS SireID, Sire.name AS Sires, Sire.ID AS IDSire " _
	& "	FROM tblDOG LEFT JOIN tblDOG AS Sire ON tblDOG.sireID = Sire.ID WHERE tbldog.name = '" & sires & "' " _
 	& " UNION " _ 
    & "SELECT 2 AS ranking, tblDOG.ID AS ID, tblDOG.name AS name, tblDOG.sireID AS SireID, Sire.name AS Sires, Sire.ID AS IDSire " _
	& "	FROM tblDOG LEFT JOIN tblDOG AS Sire ON tblDOG.sireID = Sire.ID WHERE tbldog.name LIKE '%" & sires & "%' " _ 
    & "ORDER BY ranking, Sires" 
Response.Write "DEBUG SQL: " & SRSQL & "<HR>" ' remove when it works
SireSQL = "UPDATE tblDOG LEFT JOIN tblDOG AS sire ON tblDOG.sireID = Sire.ID SET tblDOG.sireID = () WHERE sire.name =" & name & ""
Response.Write "DEBUG SQL: " & SireSQL & "<HR>" ' remove when it works

Dim objRS
Set objRS = Server.CreateObject("ADODB.recordset, ID")
objRS.Open sSQL, myConn, , adLockOptimistic

If Request.form("sires") = " " OR Request.form("sires") = "" THEN
set objrs = myconn.execute(sSQL)
Response.Write "DEBUG SQL: " & sSQL & "<HR>" ' remove when it works 
End If

Set objrs = myconn.Execute( SRSQL )

If objrs("ranking") = 1 Then 
   Response.Write "this is what will show if a dog exact matches"
Else 
  Response.Write "There a few dogs that match. Please select a dog below. <BR>"
Do While Not objRS.EOF

%> 
    <a href="parentsubmit2.asp?id=<%=request.form("ID")%>&Sire=<%=Escape(objRS("name"))%>&item=sire"><%=objRS("name")%></a><br> 
<% 	
	objRS.MoveNext
Loop
End If 
objRS.Close
Set objRS = Nothing
End Sub
myConn.close
Set myConn = nothing
%>
</body>

Just shows sire text box.... type "cross c" in text box (without quotes)

http://www.ravenswayhrc.com/parents.asp?ID=1 (url WITH case codes)
This should show list of dogs that contain cross c, but get blank page

http://www.ravenswayhrc.com/parents2.asp?ID=1 (WITHOUT case codes) This shows what I want to show at the moment

Thanks for your help






rdouglass -> RE: One more Hill (3/15/2008 13:20:42)

quote:

strAction = Request("action")


I don't see any "action" parameter. If you're trying to pick up the 'action' parameter in the <form> tag, I don't think it can be done that way. What specifically are you trying to do with that? It does look like you're trying to use that in your CASE statement but I think you may be confusing yourself with all those extra variables.

If what you're trying to do is what I think you're trying to do, then you might want to do something like this:

In your <form> tag, do something like this:

<form method="POST" name="editparents" action="parentsubmit2.asp?act=edit">

Now you should be able to dispense with those Const at the top and do something like:



Select Case Request.querystring("act")
Case "edit"
EditRecord ID
Case "blah"
AddRecord
Case Else
Response.Write "Error happend with case"
End Select

Does that help you any? Am I understanding the issue correctly?




crosscreek -> RE: One more Hill (3/15/2008 13:53:01)

With your 2nd reply I started looking into the cases & noticed I didn't need the sub stuff & had too much JUNK...You are understanding what I need.

I just couldn't figure out how to get the url to understand the different querystings...And you answered that...

If I'm thinking right

Select Case Request.querystring("act")

Case "edit" &act=edit
EditRecord ID

Case "sire" &act=sire
Code to update sire information when someone clicks on a particular dogs name

Case "sireadd" &act=sireadd
code to add sire
Will add code to add a dog without having to go to a different page & back again

Case "dam" &act=dam
same as above, but instead the dam

Case Else
Response.Write "Error happend with case"
End Select

Thank you HUG...

This give me a good start in the RIGHT direction...Thank you.






Spooky -> RE: One more Hill (3/15/2008 17:07:22)

When you write the "case" it is the 'answer' to the querystring question

eg if "act" = 'edit', then your case will be

Case "edit"
EditRecord ID


If "act" = 'sire' then your case will be :

Case "sire"
Code to update sire information when someone clicks on a particular dogs name


The case is just the literal answer to "Select Case Request.querystring("act") "






crosscreek -> RE: One more Hill (3/15/2008 17:31:40)

Gotta!!

I got the sire hyperlinks to update with the hyperlinks now... 3 more cases to go...

You know this is kinda fun when thing go right....

Thank you everyone for all your help....




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.078125