Forums

ASP

This topic is locked

Adding a message after a rcord has been inserted

Posted 19 Feb 2008 21:16:30
1
has voted
19 Feb 2008 21:16:30 Javier Castro posted:
Hey guys,

I have a form that inserts records to a SQL db. After the user, inserts a record I would like for him to receive a little message say: blah blah blah.
Where abouts in my code would I do that? problably I have to create a:
<pre id=code><font face=courier size=2 id=code> &lt;%
Dim sResponse
sResponse = "Well Done"
%&gt;</font id=code></pre id=code>



and create a condition, but I'm not sure where that would go. I have been doing it in various places, like around the redirect, but no luck. Has anyone done somethig like this if so, could you share your experience????

Thanks a bunch.

<pre id=code><font face=courier size=2 id=code>&lt;%
Dim MM_editAction
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
Dim MM_abortEdit
MM_abortEdit = false
%&gt;
&lt;%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
If condition = "" Then
MM_IIf = ifFalse
Else
MM_IIf = ifTrue
End If
End Function
%&gt;

&lt;%
If (CStr(Request("MM_insert") = "form1" Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd

Set MM_editCmd = Server.CreateObject ("ADODB.Command"
MM_editCmd.ActiveConnection = MM_connPages_STRING
MM_editCmd.CommandText = "INSERT INTO tblSRegistry (txtCompanyName, txtURL, txtPTopic, txtFirstName, txtLastName, txtTitle, txtPhone, txtemail, bitShow) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 50, Request.Form("txtCompanyName") ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 202, 1, 50, Request.Form("txtURL") ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 203, 1, 1073741823, Request.Form("txtPTopic") ' adLongVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 201, 1, 50, Request.Form("txtFirstName") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 201, 1, 50, Request.Form("txtLastName") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 202, 1, 75, Request.Form("txtTitle") ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 202, 1, 50, Request.Form("txtPhone") ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8", 202, 1, 50, Request.Form("txtemail") ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param9", 5, 1, -1, MM_IIF(Request.Form("bitShow", 1, 0)) ' adDouble
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close


' append the query string to the redirect URL
Dim MM_editRedirectUrl
MM_editRedirectUrl = "sregistry.asp"
If (Request.QueryString &lt; style="width:100%"&gt; "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
Response.Redirect(MM_editRedirectUrl)
End If
End If
%&gt;

&lt;%
Dim rsSRegistry
Dim rsSRegistry_cmd
Dim rsSRegistry_numRows

Set rsSRegistry_cmd = Server.CreateObject ("ADODB.Command"
rsSRegistry_cmd.ActiveConnection = MM_connPages_STRING
rsSRegistry_cmd.CommandText = "SELECT * FROM tblSRegistry"
rsSRegistry_cmd.Prepared = true

Set rsSRegistry = rsSRegistry_cmd.Execute
rsSRegistry_numRows = 0
%&gt;
</font id=code></pre id=code>

BTW, Using Clasic ASP, DW 8.0.2

Javier
"I'm a slow learner and I forget fast" grandpa
DW | FW | ASP | HTML | CSS

Edited by - am7555 on 19 Feb 2008 21:18:11

Edited by - am7555 on 19 Feb 2008 21:18:50

Replies

Replied 20 Feb 2008 11:25:42
20 Feb 2008 11:25:42 Alan C replied:
Hi Javier
I do php, so I struggle to read the asp, but I thought I'd put in my 10c worth anyway <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

with php setting up a database access usually ends up by forming the query as a string, then calling the function mysql_query(); it returns TRUE on success or FALSE on error, that means you can test it immediately after the database operation and send your email at that point.

Typically (in php) you might see something like

<pre id=code><font face=courier size=2 id=code> $updateSQL = sprintf("UPDATE . . . or whatever";

mysql_select_db($database_luk_connect, $luk_connect);
$Result1 = mysql_query($updateSQL, $luk_connect) or die(mysql_error());
# send your email here as you know that the query has worked
</font id=code></pre id=code>

I think I can see something like that in rsSRegistry_cmd.CommandText = "SELECT * FROM tblSRegistry which I guess is setting up a query, but I'm lost after that . . . <img src=../images/dmxzone/forum/icon_smile_sad.gif border=0 align=middle>

hope that helps

BTW I recently moved here from Edmonton - I wish I were back there - but they do say be careful what you wish for





Edited by - sitemaster on 20 Feb 2008 11:30:01
Replied 20 Feb 2008 16:57:12
20 Feb 2008 16:57:12 Javier Castro replied:
Thanks Alan,

I have looked at ways to do it: Redirecting, email and just a adding a message line. The Redirecting and email I have already done and tested. I was just a trying to see how it would work and where my lines would go. Perhaps my approach was not clear. I think that I may play around with a timed div that appears after the form is posted. Regardless if you work with PHP. here is an idea.

When you first go to the page with form, you have a function that checks the last record on your db. Then, after the form has been posted the function checks if there is a new record added and if so, it writes: "hey, you have posted a new record." This message could be in a "timed div", say 5 secs. and it close. What do you say?

Sorry. I got my head going at 100 miles, caffeine rush..I guess and needed to bounce this to another brain. Thanks for the input. <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>



Javier
"I'm a slow learner and I forget fast" grandpa
DW | FW | ASP | HTML | CSS
Replied 20 Feb 2008 20:00:10
20 Feb 2008 20:00:10 Alan C replied:
no worries, I'm still not with it, I guess my brain is worked out today, I just finished a large job and my head aches so really I ought to take a break.

Hope you get that message sorted

Reply to this topic