Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Statistics on number of pushed buttons

Status
Not open for further replies.

Jahappz

Technical User
Jun 3, 2002
133
SE
My page has acouple of posts and a button where i send an email that the posts is done to an email acount.
what i want is to have statistics on how many "send" buttons that where clicked from the page.Im thinking of having a database but how do i add 1 for every click to that database?

Can you guys give me an code example?

Dim data
Set data = conn.Execute(sql)

While Not data.EOF
%>

<tr>
<td><%=data("D4831")%></td>
<td><%=data("D4832")%></td>
<td><%=data("D18489")%></td>
<td><%if trim(data("D4835"))<>"" then response.write(trim(data("D4835"))&", ")%><%=data("D4836")%></td>
<td><%=data("D4815")%></td>
<td><%=data("D4841")%>&nbsp;</td>
<td><FORM ACTION="support.asp">
<INPUT TYPE="Hidden" NAME="To" value="my@email.com">
<INPUT TYPE="hidden" NAME="Subject" Value="Done:<%=data("D4801")%>" size="10">
<INPUT TYPE=submit NAME="Send" VALUE="Send"></td>

</form>


</tr>
<%
data.MoveNext
Wend

data.close
set data = Nothing

conn.Close
Set Conn = Nothing
%>

</table>

</BODY>
</HTML>
 
Really we need a little more information...like where does your form post to when the submit button is clicked. Here would be the basic code to perform what you're asking providing the table name is "YourTable" and the numeric field containing the number of clicks is called "ClickCounter":
Code:
dim yourConnectionString,Conn
Set Conn=Server.CreateObject("ADODB.CONNECTION")
Conn.Open yourConnectionString
dim rs,theCount,strSql
Set rs = Server.CreateObject("ADODB.Recordset")
strSql = "SELECT ClickCounter FROM YourTable"
rs.Open strSql, Conn, 3, 3
IF Not rs.eof then
	theCount = rs("ClickCounter")
	theCount = theCount + 1
	rs("ClickCounter) = theCount
	rs.Update
End If
set rs = nothing
Conn.close
set Conn = nothing

Or without the recordset object:
Code:
dim yourConnectionString,Conn
Set Conn=Server.CreateObject("ADODB.CONNECTION")
Conn.Open yourConnectionString
dim rs,theCount,strSql
strSql = "SELECT ClickCounter FROM YourTable"
Set rs = Conn.Execute(strSql)
IF Not rs.eof then
	theCount = rs("ClickCounter")
	theCount = theCount + 1
	strSql="INSERT INTO YourTable(ClickCounter) Values (" & theCount & ")"
	Conn.Execute(strSql)
End If
set rs = nothing
Conn.close
set Conn = nothing
I'm assuming that you know were this needs to go. If not please supply a little more info.
Cheers
 
Veep,

Can't his be done with just a simple UPDATE command?
Code:
strSQL = "UPDATE YourTable SET ClickCounter=ClickCounter+1"
objConn.Execute strSQL
I haven't tried it with ASP but I'm sure I've tried something similar with the SQL Panel in SQL Server.

Tony
________________________________________________________________________________
 
Here are the complete code... what i want it to do it every time someone clicks a "send" button i want to count it to another mdb database just to get a statistics ....

Is this enough information?


<%@Language=VBScript LCID=1053%>
<% Option Explicit %>
<%
dim strHost, mail, strErr, bSuccess
' change to address of your own SMTP server
strHost = "smtphost.com"
If Request("Send") <> "" Then
Set Mail = Server.CreateObject("Persits.MailSender")
' enter valid SMTP host
Mail.Host = strHost

Mail.From = "test@test.com" ' From address
Mail.FromName = "test" ' optional
Mail.AddAddress request("to")

' message subject
Mail.Subject = Request("Subject")
' message body
Mail.Body = Request("Body")
strErr = ""
bSuccess = False
On Error Resume Next ' catch errors
Mail.Send ' send message
If Err <> 0 Then ' error occurred
strErr = Err.Description
else
bSuccess = True
End If
End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>AB</TITLE>
<SCRIPT LANGUAGE="VBScript">
Sub send_OnClick
MsgBox "Done",0, "Information"
End Sub
</SCRIPT>
<link type="text/css" rel="stylesheet" href="stil.css">
</HEAD>
<BODY>
<img src="baktop1.jpg" border="0"><br>
<font face="verdana" size="2">
<% If strErr <> "" Then %>
<h3>An error has accured<% = strErr %>
<% End If %>
<% If bSuccess Then %>
<% Response.Redirect "support.asp?order=D18489" %>
<% End If %><br>
</font>
<table cellspacing="0" cellpadding="0">
<tr>
<th><a href="support.asp?order=D4831">Kundkod</a></th>
<th><a href="support.asp?order=D4832"><div align="left">Företag</div></A></th>
<th><a href="support.asp?order=D18489">Ansvarig</a></th>
<th><a href="support.asp?order=D4835,D4836">Kundkontakt</a></th>
<th><a href="support.asp?order=D4815">Problem beskrivning</a></th>
<th><a href="support.asp?order=D4841">Datum</a></th>
<th>Avslutat</th>
</tr>
<%
Dim conn

' Öppna en förbindelse med databasen
Set conn = Server.CreateObject("ADODB.Connection")
Conn.Open "pydata"


Dim sql, order
sql = "SELECT * FROM PUSELUPD Where D4807='1' and D4805='SUPPORT' Order by D18489"

if request("order")<>"" then order = " ORDER BY "&request("order")
sql = "SELECT * FROM PUSELUPD Where D4807='1' and D4805='SUPPORT'" & order



Dim data
Set data = conn.Execute(sql)

While Not data.EOF
%>

<tr>
<td><%=data("D4831")%></td>
<td><%=data("D4832")%></td>
<td><%=data("D18489")%></td>
<td><%if trim(data("D4835"))<>"" then response.write(trim(data("D4835"))&", ")%><%=data("D4836")%></td>
<td><%=data("D4815")%></td>
<td><%=data("D4841")%>&nbsp;</td>
<td><FORM ACTION="support.asp">
<INPUT TYPE="Hidden" NAME="To" value="test@test.com
<INPUT TYPE="hidden" NAME="Subject" Value="Donedata("D4801")%>" size="10">
<INPUT TYPE=submit NAME="Send" VALUE="Sendtd>
</form>


</tr>
<%
data.MoveNext
Wend

data.close
set data = Nothing

conn.Close
Set Conn = Nothing
%>

</table>

</BODY>
</HTML>
 
Couple of things:
Code:
Sub send_OnClick
MsgBox "Done",0, "Information"
End Sub
This is happening on the client-side as soon as the user clicks the button so it doesn't really mean "Done". You could still get the server-side error after they click "OK".
Code:
While Not data.EOF
%>
    <tr>
        <td><%=data("D4831")%></td>
        <td><%=data("D4832")%></td>
        <td><%=data("D18489")%></td>
        <td><%if trim(data("D4835"))<>"" then response.write(trim(data("D4835"))&", ")%><%=data("D4836")%></td>
        <td><%=data("D4815")%></td>
        <td><%=data("D4841")%>&nbsp;</td>
        <td><FORM ACTION="support.asp">
<INPUT TYPE="Hidden" NAME="To" value="test@test.com
<INPUT TYPE="hidden" NAME="Subject" Value="Donedata("D4801")%>" size="10">
<INPUT TYPE=submit NAME="Send" VALUE="Sendtd>
</form>        
    </tr>
    <%
    data.MoveNext
Wend
You've got your form, hidden fields and submit button wrapped up in a loop. If there are multiple records returned then you'll be creating multiple instances of the form (and button).

I can't be sure whether or not this page is Support.asp or not. Either way you need to add a "flag" to this querystring such as:
Code:
<% If bSuccess Then %>
<% Response.Redirect "support.asp?order=D18489[b]&GetClick=TRUE[/b]" %>
<% End If %>
Then you can stick the update code of your choice on the receiving page in a block like:
Code:
If Request.Querystring("GetClick") <> "" then
     ' database update code here
End If

 
BTW...Most important: FesterSXS is correct. My second example should have been an update using SQL like he posted instead of an INSERT. Please forgive my Spaz-attack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top