Forums

ASP

This topic is locked

Sql Update Help from asp form

Posted 01 May 2007 12:18:16
1
has voted
01 May 2007 12:18:16 ws bolt posted:
ok here is what I have so far. I'm accessing data from a SQL 2005 db svr, I can get the data, display it in a form with no problems, but I cant figure out
how to update that data within the form - sending it to another asp page to do the update or another function to update the data.

Here is the current code. What I would like to do if possible is keep it all in one, and not haveing to send the form info to another asp page, but if thats the best way so be it. If at all possible I would like to send the form data into another function.

please help - any help will be welcom.. thanks wsb

<!-- #INCLUDE FILE="common.asp" -->
<%ChooseMethod()
'Dim rsRealtors

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">

<html>
<head></head>
<body bgcolor="#FFFFFF">
<!-- Agents Content -->

<%
Select Case Method
Case "Default"
ListAll()
Case "View"
View()
End Select

adoCon.Close
Set adoCon = NOTHING
%>
<!-- End Agents Content -->
</body>
</html>


<%Sub listAgents()%>

<td valign="center" align="left" nowrap><a href="edit_agents.asp?Method=View&ID=<%=rsRealtors("ID"%>">Edit</a>&nbsp&nbsp<a href="delete.asp?Method=View&ID=<%=rsRealtors("ID"%>">Delete</a>&nbsp&nbsp<%=rsRealtors("fName"%> <%if rsRealtors("mName" <> "" then response.Write(rsRealtors("mName" & " " end if%> <%=rsRealtors("lName"%></td>


<%rsRealtors.MoveNext
End Sub


Function ListAll()

rsRealtors = "SELECT * FROM agents order by ID"
Set rsRealtors = adoCon.Execute(rsRealtors)
%>
<table width="600" border="0" cellpadding="3" cellspacing="1" align="center">
<%Do Until rsRealtors.EOF%>
<tr>
<%
listAgents()



%>
</tr>
<%loop%>
</table>
<%End Function%>



<%Function View()
rsRealtors = "SELECT * FROM agents WHERE ID = "&Request.QueryString("ID"
Set rsRealtors = adoCon.Execute(rsRealtors)

%>
<form name="AgentUpdate" method="Post" action="confirm.asp">
<table>
<tr><td>First Name: &nbsp<input type="text" name="fName" value="<%=rsRealtors("fName"%>"></td></tr>

<tr><td>Middle Int: &nbsp<input type="text" name="mName" value="<%=rsRealtors("mName"%>"></td></tr>

<tr><td>Last Name: &nbsp<input type="text" name="lName" value="<%=rsRealtors("lName"%>"></td></tr>

<tr><td>Work Ph#: &nbsp<input type="text" name="wPhone" value="<%=rsRealtors("wPhone"%>"></td></tr>

<tr><td>Work Ph# Ext#: &nbsp<input type="text" name="wPhoneExt" value="<%=rsRealtors("wPhoneExt"%>"></td></tr>

<tr><td>Home Ph#: &nbsp<input type="text" name="hPhone" value="<%=rsRealtors("hPhone"%>"></td></tr>

<tr><td>Cell Ph#: &nbsp<input type="text" name="cPhone" value="<%=rsRealtors("cPhone"%>"></td></tr>

<tr><td>Email: &nbsp<input type="text" name="email" size="75" value="<%=rsRealtors("email"%>"></td></tr>

<tr><td>Picture File Name: &nbsp<input type="text" name="fileName" size="50" value="<%=rsRealtors("fileName"%>"></td></tr>

<tr><td>Notes: &nbsp <textarea name="notes" rows="3" cols="90" ><%=rsRealtors("notes"%> </textarea> </td></tr>

<tr><td>SWMRIC #: &nbsp<input type="text" name="nSwmric" value="<%=rsRealtors("nSwmric"%>"></td></tr>

<tr ><td>SWMRIC See My Listings Address: &nbsp<input type="text" name="wSwmric" size="200" value="<%=rsRealtors("wSwmric"%>"></td></tr>

<input type="hidden" name="ID" value="<% = rsRealtors("ID" %>">

</table>

<input type="submit" name="Submit" value="Update">


</form>

<%End Function%>



this is the common.asp file if that will help..

<%@ Language = VBScript %>
<% Option Explicit %>
<!-- #INCLUDE FILE="../admin/inc/adovbs.inc" -->
<!-- #INCLUDE FILE="dbConn.asp" -->
<%
'Global Vars
'Dim strSQL

'Define Global Counter
Dim Counter
Counter = 0

'Check the Method
Dim Method,DefaultMethod
Function ChooseMethod()
Method = Request.QueryString("Method"
If Method = "" Then
Method = Request.Form("Method"
If Method = "" Then
Method = "Default"
End If
End If
End Function






Dim agents
Sub GetAgentsList
'Pull all listings for list of listings for dictionary
rsRealtors = "SELECT * FROM agents order by ID"
Set rsRealtors = adoCon.Execute(rsRealtors)

'Set agents into dictionary by ID
Set agents = Server.CreateObject("Scripting.Dictionary"

Do until rsRealtors.EOF

rsRealtors.MoveNext
loop
End Sub


%>

Replies

Replied 05 May 2007 08:33:31
05 May 2007 08:33:31 ws bolt replied:
Hi all.. well I figured it out.. here is the code.

<!-- #INCLUDE FILE="common.asp" -->
<%ChooseMethod()


%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">

<html>
<head></head>
<body bgcolor="#FFFFFF">
<!-- Agents Content -->

<%
Select Case Method
Case "Default"
ListAll()
Case "View"
View()
Case "Delete"
Delete()
Case "Update"
Update()
Case "AddAgent"
AddAgent()
Case "Add"
Add()
End Select

adoCon.Close
Set adoCon = NOTHING
%>
<!-- End Agents Content -->
</body>
</html>


<%Sub listAgents()%>

<td valign="center" align="left" nowrap><a href="edit_agents.asp?Method=View&ID=<%=rsRealtors("ID"%>">Edit</a>&nbsp&nbsp<a href="edit_agents.asp?Method=Delete&ID=<%=rsRealtors("ID"%>">Delete</a>&nbsp&nbsp<%=rsRealtors("fName"%> <%if rsRealtors("mName" <> "" then response.Write(rsRealtors("mName" & " " end if%> <%=rsRealtors("lName"%></td>


<%rsRealtors.MoveNext
End Sub



Function ListAll()

rsRealtors = "SELECT * FROM agents order by ID"
Set rsRealtors = adoCon.Execute(rsRealtors)
%>
<table width="600" border="0" cellpadding="3" cellspacing="1" align="center">
<%Do Until rsRealtors.EOF%>
<tr>
<%
listAgents()

%>
</tr>
<%loop%>
<a href="edit_agents.asp?Method=AddAgent">Add Agent</a>
</table>
<%End Function%>




<%Function View()
rsRealtors = "SELECT * FROM agents WHERE ID = "&Request.QueryString("ID"
Set rsRealtors = adoCon.Execute(rsRealtors)

%>
<form name="AgentUpdate" method="Post" action="edit_agents.asp?Method=Update&ID=<%=rsRealtors("ID"%>">
<table>
<tr><td>First Name: &nbsp<input type="text" name="fName" value="<%=rsRealtors("fName"%>"></td></tr>

<tr><td>Middle Int: &nbsp<input type="text" name="mName" value="<%=rsRealtors("mName"%>"></td></tr>

<tr><td>Last Name: &nbsp<input type="text" name="lName" value="<%=rsRealtors("lName"%>"></td></tr>

<tr><td>Work Ph#: &nbsp<input type="text" name="wPhone" value="<%=rsRealtors("wPhone"%>"></td></tr>

<tr><td>Work Ph# Ext#: &nbsp<input type="text" name="wPhoneExt" value="<%=rsRealtors("wPhoneExt"%>"></td></tr>

<tr><td>Home Ph#: &nbsp<input type="text" name="hPhone" value="<%=rsRealtors("hPhone"%>"></td></tr>

<tr><td>Cell Ph#: &nbsp<input type="text" name="cPhone" value="<%=rsRealtors("cPhone"%>"></td></tr>

<tr><td>Email: &nbsp<input type="text" name="email" size="75" value="<%=rsRealtors("email"%>"></td></tr>

<tr><td>Picture File Name: &nbsp<input type="text" name="fileName" size="50" value="<%=rsRealtors("fileName"%>"></td></tr>

<tr><td>Notes: &nbsp <textarea name="notes" rows="3" cols="90" ><%=rsRealtors("notes"%> </textarea> </td></tr>

<tr><td>SWMRIC #: &nbsp<input type="text" name="nSwmric" value="<%=rsRealtors("nSwmric"%>"></td></tr>

<tr ><td>SWMRIC See My Listings Address: &nbsp<input type="text" name="wSwmric" size="200" value="<%=rsRealtors("wSwmric"%>"></td></tr>

<input type="hidden" name="ID" value="<% = rsRealtors("ID" %>">

</table>

<input type="submit" name="Submit" value="Update">


</form>


<%End Function%>

<%Function Delete()
rsRealtors = "Delete from agents where ID = "&Request.QueryString("ID"
Set rsRealtors = adoCon.Execute(rsRealtors)%>
<%
Response.Redirect "edit_agents.asp"%>
<%End Function%>

<%Function Update()
rsRealtors = "UPDATE agents"
rsRealtors = rsRealtors & " SET fName='" & request.form("fName" &"',"
rsRealtors = rsRealtors & " mName='" & request.form("mName" & "',"
rsRealtors = rsRealtors & " lName='" & request.form("lName" & "',"
rsRealtors = rsRealtors & " wPhone='" & request.form("wPhone" & "',"
rsRealtors = rsRealtors & " wPhoneExt='" & request.form("wPhoneExt" & "',"
rsRealtors = rsRealtors & " hPhone='" & request.form("hPhone" & "',"
rsRealtors = rsRealtors & " cPhone='" & request.form("cPhone" & "',"
rsRealtors = rsRealtors & " email='" & request.form("email" & "',"
rsRealtors = rsRealtors & " fileName='" & request.form("fileName" & "',"
rsRealtors = rsRealtors & " notes='" & request.form("notes" & "',"
rsRealtors = rsRealtors & " nSwmric='" & request.form("nSwmric" & "',"
rsRealtors = rsRealtors & " wSwmric='" & request.form("wSwmric" & "'"
rsRealtors = rsRealtors & " where ID=" & request.form("ID"
Set rsRealtors = adoCon.Execute(rsRealtors)
%>

<%
Response.Redirect "edit_agents.asp"%>
<%End Function%>


<%Function AddAgent()
rsRealtors = "SELECT count(*) FROM agents"
Set rsRealtors = adoCon.Execute(rsRealtors)

%>
<form name="AgentAdd" method="Post" action="edit_agents.asp?Method=Add">
<table>
<tr><td>First Name: &nbsp<input type="text" name="fName" ></td></tr>

<tr><td>Middle Int: &nbsp<input type="text" name="mName" ></td></tr>

<tr><td>Last Name: &nbsp<input type="text" name="lName" ></td></tr>

<tr><td>Work Ph#: &nbsp<input type="text" name="wPhone" ></td></tr>

<tr><td>Work Ph# Ext#: &nbsp<input type="text" name="wPhoneExt" ></td></tr>

<tr><td>Home Ph#: &nbsp<input type="text" name="hPhone" ></td></tr>

<tr><td>Cell Ph#: &nbsp<input type="text" name="cPhone" ></td></tr>

<tr><td>Email: &nbsp<input type="text" name="email" size="75" ></td></tr>

<tr><td>Picture File Name: &nbsp<input type="text" name="fileName" size="50" ></td></tr>

<tr><td>Notes: &nbsp <textarea name="notes" rows="3" cols="90" > </textarea> </td></tr>

<tr><td>SWMRIC #: &nbsp<input type="text" name="nSwmric" ></td></tr>

<tr ><td>SWMRIC See My Listings Address: &nbsp<input type="text" name="wSwmric" size="160" ></td></tr>

<tr><td>Increment displayed number by 1: <input type="text" name="ID" ></td></tr>

</table>

<input type="submit" name="Submit" value="Add">


</form>


<%End Function%>

<%Function Add()

rsRealtors = "Insert into agents"
rsRealtors = rsRealtors & " values ('" & request.form("fName" &"',"
rsRealtors = rsRealtors & " '" & request.form("mName" & "',"
rsRealtors = rsRealtors & " '" & request.form("lName" & "',"
rsRealtors = rsRealtors & " '" & request.form("wPhone" & "',"
rsRealtors = rsRealtors & " '" & request.form("wPhoneExt" & "',"
rsRealtors = rsRealtors & " '" & request.form("hPhone" & "',"
rsRealtors = rsRealtors & " '" & request.form("cPhone" & "',"
rsRealtors = rsRealtors & " '" & request.form("email" & "',"
rsRealtors = rsRealtors & " '" & request.form("fileName" & "',"
rsRealtors = rsRealtors & " '" & request.form("notes" & "',"
rsRealtors = rsRealtors & " '" & request.form("nSwmric" & "',"
rsRealtors = rsRealtors & " '" & request.form("wSwmric" & "',"
rsRealtors = rsRealtors & " '" & request.form("ID" & "')"
Set rsRealtors = adoCon.Execute(rsRealtors)
%>

<%
Response.Redirect "edit_agents.asp"%>
<%End Function%>

Reply to this topic