PDA

View Full Version : Delete an entry, error found, undefined function


Cuttie0506
01-26-2006, 05:53 AM
hi.. i got a problem here, about deleting an entry..


I got these codes under 1 asp page:


For y=0 To UBound(ServerArray,2)
Response.write "<tr>"

Response.write "<form name=form1 action='DeleteRecord.asp' method='post'>"
Response.write "<td><input type=submit value=Delete name=submit></td>"

Response.write "<input type='hidden' name='mm_delete' value='form1'>"
Response.write "<input type='hidden' name='MM_recordId' value='ServerArray(0,y)'>"
Response.write "</form>"

Response.write "<td><input type=submit value=Edit name=submit></td>"
Response.write "<td width='3%'>" & ServerArray(0,y) & "</td>"
Response.write "<td width='3%'>" & ServerArray(1,y) & "</td>"
Response.write "<td width='3%'>" & ServerArray(2,y) & ", " & ServerArray(3,y) & "</td>"
Response.write "<td width='3%'>" & ServerArray(4,y) & "</td>"
Response.write "<td width='3%'>" & ServerArray(5,y) & "</td>"

Next

Response.write "</form>"


So when i click on the delete button, it will go to another asp page, whereby, it will execute the delete function.. with the following codes:


if (CStr(Request("MM_delete")) = "form1" And CStr(Request("MM_recordId")) <> "") Then

'Assign de variables
MM_editConnection = MM_DSPRMS_STRING
MM_editTable = "Security_Vulnerability"
MM_editColumn = "ID"
MM_recordId = "" + Request.Form("MM_recordId") + ""

End If

'Delete Record: construct a sql delete statement and execute it

If (CStr(Request("MM_delete")) <> "" And CStr(Request("MM_recordId")) <> "") Then

'Create the sql delete statement
MM_editQuery = "delete from " & MM_editTable & " where " & MM_editColumn & " = " & MM_recordId

If (Not MM_abortEdit) Then
' execute the delete
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

End If


However, it will have 1 error, Undefined Function: ServerArray (found under the delete page).

Do any1 know how to solve this prob?

Thanx

glenngv
01-26-2006, 09:19 AM
Change this:
Response.write "<input type='hidden' name='MM_recordId' value='ServerArray(0,y)'>"

to:
Response.write "<input type='hidden' name='MM_recordId' value='" & ServerArray(0,y) & "'>"
What happened was the hidden field's value is the literal string "ServerArray(0,y)". If you temporarily set the field type to text, you can see the wrong value. And then this is passed to the DELETE statement

delete from Security_Vulnerability where ID = ServerArray(0,y)
The SQL server thinks it is an SQL function but it's not, thus the undefined function error.

Cuttie0506
01-27-2006, 01:44 AM
Okay, thanx..
It works now.. ^^