Forums
This topic is locked
Updating Records!
Posted 19 Mar 2006 22:24:37
1
has voted
19 Mar 2006 22:24:37 michael Sinton posted:
Hi,Here we go, I am using an access database and dreamweaver.
I currently have a page with a no. if DIV's in it, which contain information read from my database - I have this part working ok.
Also in my DIV's I have a login button for "Shop Members", when this is clicked it brings up a Login Page, were a username and password are entered, these are then checked against my database and if correct, the "Shop Member" is brought to an update page, were they are able to update there DIV content(Just one field "DIV code" in the database to display different information in their DIV. But when I click update it just updates the first record in the database. Which is not what I want.
What I want to happen is when the "shop member" logs in and are brought to the update page and they click the update button, the only record which is updated is the one which links to there username and password, which they entered when they logged in! AND NOT THE FIRST RECORD IN THE DATABASE!
Any help would be greatly appreciated.
Thanks
Michael.
Replies
Replied 20 Mar 2006 17:37:49
20 Mar 2006 17:37:49 Javier Castro replied:
Can you post some code for us to see?
Replied 20 Mar 2006 18:04:41
20 Mar 2006 18:04:41 michael Sinton replied:
<pre id=code><font face=courier size=2 id=code>
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/connReg.asp" -->
<%
' *** Edit Operations: declare variables
Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd
Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId
Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME")
If (Request.QueryString <> "" Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Update Record: set variables
If (CStr(Request("MM_update") = "form1" And CStr(Request("MM_recordId") <> "" Then
MM_editConnection = MM_connReg_STRING
MM_editTable = "Shop_Reg"
MM_editColumn = "ID_No"
MM_recordId = "" + Request.Form("MM_recordId" + ""
MM_editRedirectUrl = "thankyou_for_update.asp"
MM_fieldsStr = "Page_Code|value"
MM_columnsStr = "Page_Code|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|"
MM_columns = Split(MM_columnsStr, "|"
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
' *** Update Record: construct a sql update statement and execute it
If (CStr(Request("MM_update") <> "" And CStr(Request("MM_recordId") <> "" Then
' create the sql update statement
MM_editQuery = "update " & MM_editTable & " set "
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),","
MM_delim = MM_typeArray(0)
If (MM_delim = "none" Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none" Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none" Then MM_emptyVal = ""
If (MM_formVal = "" Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "" Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'" Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''" & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formVal
Next
MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId
If (Not MM_abortEdit) Then
' execute the update
Set MM_editCmd = Server.CreateObject("ADODB.Command"
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
Dim rsupdate
Dim rsupdate_numRows
Set rsupdate = Server.CreateObject("ADODB.Recordset"
rsupdate.ActiveConnection = MM_connReg_STRING
rsupdate.Source = "SELECT * FROM Shop_Reg"
rsupdate.CursorType = 0
rsupdate.CursorLocation = 2
rsupdate.LockType = 1
rsupdate.Open()
rsupdate_numRows = 0
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form method="post" action="<%=MM_editAction%>" name="form1">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Page_Code:</td>
<td>
<input type="text" name="Page_Code" value="<%=(rsupdate.Fields.Item("Page_Code".Value)%>" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td>
<input type="submit" value="Update record">
</td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="MM_recordId" value="<%= rsupdate.Fields.Item("ID_No".Value %>">
</form>
<p> </p>
</body>
</html>
<%
rsupdate.Close()
Set rsupdate = Nothing
%>
</font id=code></pre id=code>
Replied 20 Mar 2006 18:07:11
20 Mar 2006 18:07:11 michael Sinton replied:
Sorry forgot to mention the above code is from my update page were the "shop Member" updates there code in the database.
Replied 20 Mar 2006 22:16:59
20 Mar 2006 22:16:59 Javier Castro replied:
I'm not clear as to what you are asking so I'll try to recap:
Once user logs in, they get to an update page, where they can modify their profile, right. At this point it is only showing the first record info and not the user's profile.
This could most likely be because you have not set a session ID that you can use to identify each user with their respective profile.
What is in the Table = "Shop_Reg" Username and Password only?
Once user logs in, they get to an update page, where they can modify their profile, right. At this point it is only showing the first record info and not the user's profile.
This could most likely be because you have not set a session ID that you can use to identify each user with their respective profile.
What is in the Table = "Shop_Reg" Username and Password only?
Replied 21 Mar 2006 16:12:28
21 Mar 2006 16:12:28 michael Sinton replied:
Sorry bout the late reply but managed to get it sorted ok,
Used session variable on the Username when they logged in.
Thanks.
Used session variable on the Username when they logged in.
Thanks.