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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert query - can't spot the error

Status
Not open for further replies.

kkinnea

Programmer
Sep 30, 2002
25
0
0
US
I am unable to spot the error in this query:

<% Dim strConnection, strQuery, Title, StartDate, EndDate, StartTime, EndTime, Address1, Address2, City, State, Website, Info

if Request.Form(&quot;evTitle&quot;) <> &quot;&quot; then Title = chr(39) & Request.Form(&quot;evTitle&quot;) & chr(39) else Title = null end if
if Request.Form(&quot;evStartDate&quot;) <> &quot;&quot; then StartDate = chr(35) & Request.Form(&quot;evStartDate&quot;) & chr(35) else StartDate = null end if
if Request.Form(&quot;evEndDate&quot;) <> &quot;&quot; then EndDate = chr(35) & Request.Form(&quot;evEndDate&quot;) & chr(35) else EndDate = null end if
if Request.Form(&quot;evStartTime&quot;) <> &quot;&quot; then StartTime = chr(35) & Request.Form(&quot;evStartTime&quot;) & chr(35) else StartTime = null end if
if Request.Form(&quot;evEndTime&quot;) <> &quot;&quot; then EndTime = chr(35) & Request.Form(&quot;evEndTime&quot;) & chr(35) else EndTime = null end if
if Request.Form(&quot;evAddress1&quot;) <> &quot;&quot; then Address1 = chr(39) & Request.Form(&quot;evAddress1&quot;) & chr(39) else Address1 = null end if
if Request.Form(&quot;evAddress2&quot;) <> &quot;&quot; then Address2 = chr(39) & Request.Form(&quot;evAddress2&quot;) & chr(39) else Address2 = null end if
if Request.Form(&quot;evCity&quot;) <> &quot;&quot; then City = chr(39) & Request.Form(&quot;evCity&quot;) & chr(39) else City = null end if
if Request.Form(&quot;evState&quot;) <> &quot;&quot; then State = chr(39) & Request.Form(&quot;evState&quot;) & chr(39) else State = null end if
if Request.Form(&quot;evWebsite&quot;) <> &quot;&quot; then Website = chr(39) & Request.Form(&quot;evWebsite&quot;) & chr(39) else Website = null end if
if Request.Form(&quot;evInfo&quot;) <> &quot;&quot; then Info = chr(39) & Request.Form(&quot;evInfo&quot;) & chr(39) else Info = null end if

set con = server.createObject(&quot;ADODB.Connection&quot;)
con.open (&quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; & _
&quot;Data Source=&quot; & Server.MapPath(&quot;\db\umfa.mdb&quot;) & &quot;;&quot; & _
&quot;Persist Security Info=False&quot;)

strQuery = &quot;INSERT INTO events (evActive_Ind, evTitle) VALUES ('N',&quot; & Title & &quot;);&quot;

con.Execute(strQuery)

%>

it produces one of 2 errors:
with the variable:
Microsoft JET Database Engine error '80040e14'

Syntax error in INSERT INTO statement.

/test/events/add-event-end.asp, line 22

with a string replacing the variable:
Microsoft JET Database Engine error '80004005'

Operation must use an updateable query.

/test/events/add-event-end.asp, line 22

Any help would be appreciated.

Kristen
 
do a response.write on the sql before your query the db.

and i think you should add ' around the title.
like so:

strQuery = &quot;INSERT INTO events (evActive_Ind, evTitle) VALUES ('N','&quot; & Title & &quot;');&quot;
 
i think you need single quote around the &quot;title&quot; variable, like this (assuming that evTitle is a text field):

strQuery = &quot;INSERT INTO events (evActive_Ind, evTitle) VALUES ('N','&quot; & Title & &quot;');&quot;
 
robi2 and bbolte,

Thanks for the advice. I actually have the single quotes added into my variable (I'm also checking for nulls there too) towards the top of the code:

if Request.Form(&quot;evTitle&quot;) <> &quot;&quot; then Title = chr(39) & Request.Form(&quot;evTitle&quot;) & chr(39) else Title = null end if

I've never used a response.write statement but I'll try it. This is the first time I've attempted an update query through ASP; usually I just do SELECTS.

Kristen
 
use a response.write and then
response.End()
this will show only upto the query
 
Kristen,

In this statement:

if Request.Form(&quot;evTitle&quot;) <> &quot;&quot; then Title = chr(39) & Request.Form(&quot;evTitle&quot;) & chr(39) else Title = null end if

you have set Title = null. If I recall correctly, you cannot set a variable equal to null, I think you should set it equal to &quot;&quot; or something equivalent. Or perhaps state

if Request.Form(&quot;evTitle&quot;) <> &quot;&quot; then Title = chr(39) & Request.Form(&quot;evTitle&quot;) & chr(39) else Title is null end if

Unfortunately, I cannot test this at the moment, but you might want to check this. However, for future reference, a null cannot equal a null, therefore, you probably shouldn't set variables equal to null. Just a thought.

HTH

Everything is absolute. Everything else is relative.
 
Thanks to everyone who replied!

The key turned out to be the following error message:

Microsoft JET Database Engine error '80004005'

Operation must use an updateable query.

/test/events/add-event-end.asp, line 22

The host I am using, by default, does not set write permissions to db folders. I requested they do so, and the query now works as expected.

Kristen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top