Question : Save record to another table before deleting the record...

Hi guys.

I have some trouble with my MySQL code. Before deleting a record from a table "tbl_oae_1", I want to save that record into another table "tbl_oae_1_log", and each value must have the word "DELETED" added. I keep getting syntax errors... I admit it looks somewhat messy, so just go ahead and have a laugh. ;-) Here's my code (or attempt):

Dim xusername, xpatient_id_oae1, xspecify1, xoae1_grade
      xoae1_id = Request.Form("MM_recordId")
      sConnString = MM_conn_STRING
      Set objConn = Server.CreateObject("ADODB.Connection")
      objConn.Open(sConnString)
      sSQL = "(SELECT username AS xusername, patient_id_oae1 AS xpatient_id_oae1, specify1 AS xspecify1, oae1_grade AS xoae1_grade FROM tbl_oae_1 WHERE oae1_id = [MM_recordId])"
      sSQL1 = "INSERT INTO tbl_oae_1_log (username, patient_id_oae1, specify1, oae1_grade) VALUES (CONCAT('" & xusername & "',' DELETED'),CONCAT('" & xpatient_id_oae1 & "',' DELETED'),CONCAT('" & xspecify1 & "',' DELETED'),CONCAT('" & xoae1_grade & "',' DELETED'))"
      sSQL2 = "DELETE FROM tbl_oae_1 WHERE oae1_id = '" & xoae1_id & "'"
      response.write sSQL
      response.write sSQL1
      response.write sSQL2
      objConn.execute(sSQL)
      objConn.execute(sSQL1)
      objConn.execute(sSQL2)
      If err.number=0 Then
      response.write "the data was deleted successfully."
      End If
      objConn.Close
      Set objConn = nothing

I'm using classic asp mixed with javascripts and vb.

Best regards

Ullenulle

Answer : Save record to another table before deleting the record...

Try this
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
xoae1_id = replace(Request.Form("MM_recordId"),"'","''")
sConnString = MM_conn_STRING
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open(sConnString) 
sSQL = "(SELECT username AS xusername, patient_id_oae1 AS xpatient_id_oae1, specify1 AS xspecify1, oae1_grade AS xoae1_grade FROM tbl_oae_1 WHERE oae1_id = '" & xoae1_id & "'"
response.write sSQL
Set rs=objConn.execute(sSQL)
if not rs.eof then
  sSQL1 = "INSERT INTO tbl_oae_1_log (username, patient_id_oae1, specify1, oae1_grade) VALUES (CONCAT('" & replace(rs("xusername"),"'","''") & "',' DELETED'),CONCAT('" & replace(rs("xpatient_id_oae1"),"'","''") & "',' DELETED'),CONCAT('" & replace(rs("xspecify1"),"'","''") & "',' DELETED'),CONCAT('" & replace(rs("xoae1_grade"),"'","''") & "',' DELETED'))"
  response.write sSQL1
  objConn.execute(sSQL1)
  sSQL2 = "DELETE FROM tbl_oae_1 WHERE oae1_id = '" & xoae1_id & "'"
  response.write sSQL2
  objConn.execute(sSQL2)
end if
If err.number=0 Then
response.write "the data was deleted successfully."
End If
objConn.Close
Set objConn = nothing
Random Solutions  
 
programming4us programming4us