Forums

ASP

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>

&lt;%@LANGUAGE="VBSCRIPT"%&gt;
&lt;!--#include file="../Connections/connReg.asp" --&gt;
&lt;%
' *** 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 &lt;&gt; "" 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 = ""
%&gt;
&lt;%
' *** Update Record: set variables

If (CStr(Request("MM_update") = "form1" And CStr(Request("MM_recordId") &lt;&gt; "" 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 &lt;&gt; "" And Request.QueryString &lt;&gt; "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString &lt;&gt; "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%&gt;
&lt;%
' *** Update Record: construct a sql update statement and execute it

If (CStr(Request("MM_update") &lt;&gt; "" And CStr(Request("MM_recordId") &lt;&gt; "" 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 &lt;&gt; "" 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 &lt;&gt; 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 &lt;&gt; "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%&gt;
&lt;%
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
%&gt;
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form method="post" action="&lt;%=MM_editAction%&gt;" name="form1"&gt;
&lt;table align="center"&gt;
&lt;tr valign="baseline"&gt;
&lt;td nowrap align="right"&gt;Page_Code:&lt;/td&gt;
&lt;td&gt;
&lt;input type="text" name="Page_Code" value="&lt;%=(rsupdate.Fields.Item("Page_Code".Value)%&gt;" size="32"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="baseline"&gt;
&lt;td nowrap align="right"&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;
&lt;input type="submit" value="Update record"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;input type="hidden" name="MM_update" value="form1"&gt;
&lt;input type="hidden" name="MM_recordId" value="&lt;%= rsupdate.Fields.Item("ID_No".Value %&gt;"&gt;
&lt;/form&gt;
&lt;p&gt;&nbsp;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;%
rsupdate.Close()
Set rsupdate = Nothing
%&gt;

</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?
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.

Reply to this topic