Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Hyperlink onclick write to database

Posted on 2005-02-28
10
Medium Priority
?
319 Views
Last Modified: 2006-11-17
Hi there,

I want to write to the database when a hyperlink is clicked

ie
<a href="mailto:joebloggs@joebloggs.com">Email</a>

<%
      set conn = server.createobject("adodb.connection")
      conn.open MM_Directory_STRING
      SQL = "INSERT INTO webDirectoryEmail(CompanyID) VALUES ('" & (StandardResults.Fields.Item("Member_ID").Value) &"')"
      conn.execute SQL
      conn.close
%>

Many thanks

Max
0
Comment
Question by:MaximusMeridus
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 7

Expert Comment

by:rohanbairat3
ID: 13421001
You can create a seperate page which has the code to write to the database ... and on  hyperlink click write a javascript to send the information to be written to the other page.
0
 
LVL 13

Accepted Solution

by:
nurbek earned 800 total points
ID: 13421038
you need a form submission

try this

<%
If LCase(Request.ServerVariables("REQUEST_METHOD")) = "post" Then
Email = Request.Form("email")
     set conn = server.createobject("adodb.connection")
     conn.open MM_BCCBDirectory_STRING
     SQL = "INSERT INTO webDirectoryEmail(CompanyID) VALUES ('" & email) &"')"
     conn.execute SQL
     conn.close
End If
%>
<form name="form1" method="post" action="">
<a href="#" onClick="document.form1.submit();">Email
  </a>
  <p>
    <input name="email" type="hidden" id="email" value="my@email.com">
</p>
</form>
0
 
LVL 7

Expert Comment

by:rohanbairat3
ID: 13421076
<a href="javascript:SendInfo('info')">
function SendInfo(info)
{

        URL =  "page.asp?Info="+info
  parent.location = URL
}

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:MaximusMeridus
ID: 13421154
Hi there,

I did think of this, however I wanted to stay on the same page and if a page pops up it must close afterward immediately. If there no way it can be done on the same page?

Max
0
 
LVL 7

Expert Comment

by:rohanbairat3
ID: 13421185
The Solution provided by nurbek  should work ...

Are you doing other things on the form ....

And yes it is possible to open a popup page and hide it from user and close it once the task is done ...

let me know if you need some code for that..

-rohan
0
 
LVL 13

Expert Comment

by:nurbek
ID: 13421192
have you tried mine?

you may define the form action on the same page
<form name="form1" method="post" action="mypage.asp">

and put the code above (top) of your asp page
0
 
LVL 5

Assisted Solution

by:web4net
web4net earned 800 total points
ID: 13421307
I agree with rohanbairat3 .

I would do it a little different. This way, the link works even in older browsers.

=========================
   Link Pages
=========================

<html>
<head>
<script language="JavaScript">
function SendInfo(url,memberid)
{
       parent.location = "linksmanager.asp?url="+url+"&memberid="+memberid
}
</script>
</head>
<body>
<a href="mailto:joebloggs@joebloggs.com" onclick="SendInfo(this.href,'<%=Member_ID%>')">
</body>
</html>

=========================
   Links Manager
=========================
<%
     set conn = server.createobject("adodb.connection")
     conn.open MM_Directory_STRING
     SQL = "INSERT INTO webDirectoryEmail(CompanyID) VALUES ('" & Request.QueryString("Member_ID") &"')"
     conn.execute SQL
     conn.close

     Response.Redirect Request.QueryString("url")
%>
0
 
LVL 5

Expert Comment

by:web4net
ID: 13421323
wait ... Use IFRAME
0
 
LVL 9

Assisted Solution

by:cb1393
cb1393 earned 400 total points
ID: 13421354
Do you mean you want the page to not be refreshed? You might try this:

<IMG SRC="" HEIGHT="1PX" WIDTH="1PX" ID="DB_IMG">
<A HREF="#" onClick="document.all.DB_IMG.src='write_to_db.asp?email=my@email.com'">Write to the database</A>

<-------------------------------- Place the following in write_to_db.asp -------------------------------->
<%
email = Request.QueryString("email")
If email <> "" Then
     set conn = server.createobject("adodb.connection")
     conn.open MM_BCCBDirectory_STRING
     SQL = "INSERT INTO webDirectoryEmail(CompanyID) VALUES ('" & email) &"')"
     conn.execute SQL
     conn.close
End If
%>
0
 
LVL 5

Assisted Solution

by:web4net
web4net earned 800 total points
ID: 13421371
The following way you never leave the page.

=========================
   Link Pages
=========================

<html>
<head>
<script language="JavaScript">
function SendInfo(url,memberid)
{
       document.getElementById(LinkIFrame).src='linksmanager.asp?url='+url+'&memberid='+memberid;
}
</script>
</head>
<body>
<a href="mailto:joebloggs@joebloggs.com" onclick="SendInfo(this.href,'<%=Member_ID%>')">

<iframe id="LinkIFrame"
  name="LinkIFrame"
  style="width:0px; height:0px; border: 0px"
  src="blank.html"></iframe>

</body>
</html>

=========================
   linksmanager.asp
=========================
<%
     set conn = server.createobject("adodb.connection")
     conn.open MM_Directory_STRING
     SQL = "INSERT INTO webDirectoryEmail(CompanyID) VALUES ('" & Request.QueryString("Member_ID") &"')"
     conn.execute SQL
     conn.close

     Response.Redirect Request.QueryString("url")
%>
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Integration Management Part 2
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question