Database Register
Script for Saving
The file you set in the database register’s value Save, will be called by Consolo when the user saves an existing or new post with the form defined in Script for Editing.
Request sent to the script by POST:
- Consolo sends the password in the configuration as a variable password. Verify it in the script.
-
When saving an existing post, Consolo will send an ID-value to the script. The value is retrieved from the first column in the List-script. If a new post is created in the register, Consolo will request the script without an ID-value.
-
Consolo will send the whole xml-code in a variable called data. Analyze this xml-data in ASP and XML, and save the variables in the database.
Response from the script should be given in the following format:
<?xml version="1.0" encoding="ISO-8859-1"?>
<RESPONSE>
<RESULT>0/1</RESULT>
<MESSAGE>Message</MESSAGE>
<ID>Id</ID>
</RESPONSE>
- The value RESULT must be 0 or 1, decides wether the data has been saved or not.
- The value MESSAGE contains a new message for the editor.
- The value ID decides what id-number a new post will get. If editing an existing post, you just set the incoming id-number here.
Thanks to this solution, you can verify the information that is sent and alert the user about what went wrong and should be corrected.
Exemple
The example shows how to create a script for saving in SQL-connected ASP. If you are using another environment on your server, please translate the script to the suitable language.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- #INCLUDE VIRTUAL= '/consolo/db_opendb.asp'-->
<% If Request("password") <> "abc123" Then Response.End
tId = Request("id")
Set xmlDoc = Server.CreateObject("msxml2.DOMDocument")
xmlDoc.async = False
If xmlDoc.loadXML(Request("data")) Then
Set xmlNodes = xmlDoc.childNodes
aTitle = xmlDoc.getElementsByTagName("Title_VC").item(0).Text
aText = xmlDoc.getElementsByTagName("Text_VC").item(0).Text
aDate = xmlDoc.getElementsByTagName("Date_VC").item(0).Text
aNewspaper = xmlDoc.getElementsByTagName("Newspaper_VC").item(0).Text
If tId = "" Then
' New object
SQLstr = "INSERT INTO Presscutting_T (Title_VC, Text_VC, Date_VC, Newspaper_VC) VALUES (" & SSQn(aTitle) & SSQc(aText) & SSQc(aDate) & SSQc(aNewspaper) & ")"
Connect.Execute(SQLstr)
Set RS = Connect.Execute("SELECT MAX(Presscutting_ID) As New_ID FROM Arbetsliv_Presscutting_T")
tId = RS("New_ID")
Else
' Save to existing object
SQLstr = "UPDATE Presscutting_T SET "
SQLstr = SQLstr & "Title_VC = " & SSQn(aTitle)
SQLstr = SQLstr & ", Text_VC = " & SSQn(aText)
SQLstr = SQLstr & ", Date_VC = " & SSQn(aDate)
SQLstr = SQLstr & ", Newspaper_VC = " & SSQn(aNewspaper)
SQLstr = SQLstr & " WHERE Presscutting_ID = " & tId
Connect.Execute(SQLstr)
End If
%>
<RESPONSE>
<RESULT>1</RESULT>
<MESSAGE>Data has been saved.</MESSAGE>
<ID><%=tId%></ID>
</RESPONSE>
<% Else %>
<RESPONSE>
<RESULT>0</RESULT>
<MESSAGE>Error, data could not be saved</MESSAGE>
<ID><%=tId%></ID>
</RESPONSE>
<% End If
Function SSQn(str)
str = Replace(str, "'", """")
SSQn = "'" & str & "'"
End Function
Function SSQc(str)
str = Replace(str, "'", """")
SSQc = ", '" & str & "'"
End Function
%>