|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Update does not update
Hello all,
I'm dealing, probably very simple, a problem. I'm new to asp programming, so I hope you can help me. What I'm trying to do: I have selected one record on the asp page and I want to replace that and save it to the same record. It is a table with two fields (Website and Updwebsite). When I open the page, the correct data I want to edit is given, but when I change that and submit, the same data is returned and I even don't get an error on the page. So, I think it has something to do with the update query. This is the code: Code:
<%
' *** Update Record: set variables
If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then
MM_editConnection = MM_classifieds_STRING2
MM_editTable = "OCCASION"
MM_editColumn = "Updwebsite"
MM_recordId = "'" + Request.Form("MM_recordId") + "'"
MM_editRedirectUrl = "main.asp"
MM_fieldsStr = "Updwebsite|value"
MM_columnsStr = "Updwebsite|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(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 i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),",")
Delim = MM_typeArray(0)
If (Delim = "none") Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none") Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none") Then EmptyVal = ""
If (FormVal = "") Then
FormVal = EmptyVal
Else
If (AltVal <> "") Then
FormVal = AltVal
ElseIf (Delim = "'") Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''") & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(i) & " = " & 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
%>
Thanks Last edited by pjansen : August 11th, 2003 at 11:56 AM. |
|
#2
|
||||
|
||||
|
1) Always put your code inside [.code] [/.code] tags, to make it easier to read.
2) Only post the relevant code for your problem. Since you're asking about the Update statement, post the update code, and the code immediately around it, then more if asked. 3) I don't think you can use logic in your Update query in the way that you are attempting to. However, I can make very little sense of your code overall. You need more comments, and a better description of what you are trying to do.
__________________
--Dave-- U2kgSG9jIExlZ2VyZSBTY2lzLCBOaW1pdW0gRXJ1ZGl0aW9uaXMgSGFiZXM= |
|
#3
|
|||
|
|||
|
OK, I changed the first message.
|
|
#4
|
||||
|
||||
|
1. Forgot to mention this- the code tags need to have the "." removed, I just put in the dot so you could see the tags, not the result.
2. I don't see why you have all the logic in your sql statement. The syntax for your statement should be Code:
UPDATE tablename SET columnname=new_value WHERE columnname=some value You could make the new value a variable, if you are updating with data from a form or something. Perform the logic operations to determine the value of the variable before your SQL statement, so you don't have a bunch of If-Then statements inside your update. HTH |
|
#5
|
|||
|
|||
|
I fixed it.
It was, that's my opinion, something stupid because in another table it was working. The code was: Code:
MM_editQuery = "update " & MM_editTable & " set " Now it is: Code:
MM_editQuery = "update " + MM_editTable + " set " Replacing the & to + is enough but it took me almost 3 hours. Thanks for all the help P. Jansen |
|
#6
|
||||
|
||||
|
Yeah, the concatenation symbol is not the same for all database software. I just assumed you were using sql server or something similar. My mistake. In future posts, though, it would be a good idea to include which database you are using.
Glad you fixed it ![]() Last edited by karsh44 : August 11th, 2003 at 02:15 PM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Update does not update |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|