General discussion

Locked

ASP TO EMAIL AND DATABASE ERROR

By rmg ·
I am trying to post data to a database and email it at the same time from a web page form. I get an error when I try to do this. Help!

Here is the form page:

<html>
<head>
</head>
<body>
<form method="post" action="esender.asp">
<input type="text" name="rcptaddr"><!--Field for recipient address--><BR />
<input type="text" name="sndraddr"><!--Field of sender's address--> <BR />
<input type="text" name="subject"><!--Field for subject--> <BR />
<input type="text" name="body"><!--Field for body--> <BR />
<input type="submit" value="Submit">
</form>
</body>
</html>

Here is the action page:

<%@ Language=VBScript %>
<%
dim connectstr

connectstr="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=emails;Data Source=VCSESUPPLYCHAIN"
dim conn
set conn=server.createobject("adodb.connection")
with conn

.open connectstr
.execute "INSERT INTO emailtrack(To,From,Subject,Body) Values('" & request("rcptaddr") & "','" & request("sndraddr") & "','" & request("subject") & "','" & request("body") & "')"

.close
end with
set conn=nothing

dim objsendmail
set objsendmail=server.CreateObject("cdonts.newmail")
objsendmail.To="ryan_gardner@non.hp.com"
objsendmail.From="ryan_gardner@non.hp.com"
objsendmail.Subject="This is a test"
objsendmail.Body="This is the body of the test"
objsendmail.Send
%>

Here is the error I get:

Microsoft OLE DB Provider for SQL Server error '80040e14'

Incorrect syntax near the keyword 'To'.

/buypower/apptest/esender.asp, line 11

What can I do to fix this?!?

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

ASP TO EMAIL AND DATABASE ERROR

by rmg In reply to ASP TO EMAIL AND DATABASE ...

Point value changed by question poster.

Collapse -

ASP TO EMAIL AND DATABASE ERROR

by MadestroITSolutions In reply to ASP TO EMAIL AND DATABASE ...

My dear friend, for your future reference, when you get this type of error ("incorrect syntax...") it usually refers to your SQL statement.
You are requesting values from a FORM. The correct syntax is:

Request.form("MyField")

You are writing:

Request("MyField")

You can retrieve values from either form or querystring, so you need to tell the request object what collection you are retrieving the field from.

Also, If I was you, I would do it with an ADO recordset. For some reason Insert SQL statements tend to yield errors all the time. I have done countless projects with them, and I still have problems when I use them with ADO connections, so create an ADO recordset object, use the Addnew method, assign the values to the fields ( Rs01.fields(0) = xxx ) issue the Update method and thats it!

Try it, and if you have any other problems, feel free to drop a line at: webmaster@KingsDistributors.com

Good luck!

Collapse -

ASP TO EMAIL AND DATABASE ERROR

by rmg In reply to ASP TO EMAIL AND DATABASE ...

Poster rated this answer

Collapse -

ASP TO EMAIL AND DATABASE ERROR

by rmg In reply to ASP TO EMAIL AND DATABASE ...

This question was closed by the author

Back to Web Development Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums