Jump to content

Automatic insert


shaneR

Recommended Posts

HI Everyone,I've built a site using asp and vbscript and what i need to do is have some information automatically submitted to my database upon the user arriving on the desired page.At the moment the information is automatically collected but to submit it into my database im using a form which requires the submit button to be pressed.Any ideas please?

Link to comment
Share on other sites

HI Everyone,I've built a site using asp and vbscript and what i need to do is have some information automatically submitted to my database upon the user arriving on the desired page.At the moment the information is automatically collected but to submit it into my database im using a form which requires the submit button to be pressed.Any ideas please?
It would be nice to see the code on the page you're trying to submit. I can't think of any reason why the submit button would need to be pressed, unless you're assigning your variables like this:
someVar = Request.Form("something")

You aren't required to use Request.Form, you can use this instead:

someVar = Request("something")

So, when a user visits your page, you can put something like this at the top:

dim user, monkey, IPAddress, sql'Initializing and escaping variablesuser = Replace(request("user"), "'", "'')monkey = Replace(request("monkey"), "'", "'')IPAddress = Replace(Request.ServerVariables("REMOTE_ADDR"), "'", "'')'Putting them into an SQL statementsql = "INSERT INTO table (user, monkey, IP) values ('[user]', '[monkey]', '[ipAddress]')"sql = replace(sql, "[user]", user, 1, -1, vbTextCompare)sql = replace(sql, "[monkey]", monkey, 1, -1, vbTextCompare)sql = replace(sql, "[IPAddress]", IPAddress, 1, -1, vbTextCompare)'Executing statementConn.Open someDSNConn.Execute(sql)Conn.Close

Link to comment
Share on other sites

The below code is what im using and the insert into database code im sitting above this!

<form method="post" action="<%=MM_editAction%>" name="form1">          <table align="center">            <tr valign="baseline">              <td nowrap align="right">Clickdate:</td>              <td>                <input type="text" name="clickdate" value="<% Response.Write(Now) %>" size="32">              </td>            </tr>            <tr valign="baseline">              <td nowrap align="right">Ip:</td>              <td>                <input type="text" name="ip" value="<% Response.Write(Request.ServerVariables("REMOTE_ADDR")) %>" size="32">              </td>            </tr>            <tr valign="baseline">              <td nowrap align="right">Pageurl:</td>              <td>                <input type="text" name="pageurl" value="<% Response.Write(Request.ServerVariables("SCRIPT_NAME")) %>" size="32">              </td>            </tr>            <tr valign="baseline">              <td nowrap align="right">Username:</td>              <td>                <input type="text" name="username" value="<%= strLoggedInUserName %>" size="32">              </td>            </tr>            <tr valign="baseline">              <td nowrap align="right"> </td>              <td>                <input type="submit" value="Insert record">              </td>            </tr>          </table>          <input type="hidden" name="MM_insert" value="form1">        </form>

Link to comment
Share on other sites

If you want to insert the default values, that's really no different then any other database call. I'm not sure what the problem is. Once you have your database object created, however you want to create it, just use those values in the insert statement.db.open("INSERT INTO table (clickdate, ip, pageurl, username) VALUES ('" & Now & "', '" & Request.ServerVariables("REMOTE_ADDR") & "', '" & Request.ServerVariables("SCRIPT_NAME") & "', '" & strLoggedInUserName & "')")

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...