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

ASP-MSAccess Add rec to table not working!

Status
Not open for further replies.

selaine

Programmer
Oct 11, 2001
85
US
I am a newbie with ASP/VBScript and am trying to create a test page that will add a record to a table. I plan on using these concept for something real later and can't figure out whats wrong with my code. My intent is to use ADO (also new to me). I've created a System DSN called "TestAdd", my MS Access database is called "NameColor.mdb" and the table name is ""tblsqladd". There are four fields in the table 1=id 2=FirstName 3=lastName and 4=FavoriteColor. Could someone please help me figure out what I've done wrong!

The code for my input form page (called default.asp) is this:

<html>
<head><title>Test Adding a Record to Table</title></head>
<body>
<h3 align=&quot;center&quot;>SQL Add example</h3>
<td width=&quot;424&quot;><form method=&quot;post&quot; name=&quot;form1&quot; action=&quot;addrecord.asp&quot;>
<p><strong>First Name</strong><br>
<input type=&quot;text&quot; size=&quot;40&quot; name=&quot;txtFirst&quot;><br>
<strong>Last Name</strong><br>
<input type=&quot;text&quot; size=&quot;40&quot; name=&quot;txtLast&quot;><br>
<strong>FavoriteColor</strong><br>
<input type=&quot;text&quot; size=&quot;40&quot; name=&quot;txtColor&quot;><br>
<p><input type=&quot;Submit&quot; value=&quot;Submit New Example&quot; name&quot;b1&quot;> </font></p>
</form>
</td>
</tr>
</table>
</center></div>
</body>
</html>

My code for addrecord.asp is this:
<%
Option Explicit

'Declare variables
Dim strFName
Dim strLName
Dim strColor
Dim SQLINSERT
Dim connupdate

'Grab variables from the querystring.
strFName=Request.Querystring(&quot;txtFirst&quot;)
strLName=Request.Querystring(&quot;txtLast&quot;)
strColor=Request.Querystring(&quot;txtColor&quot;)

'Create the INSERT statement for a brand new client.
SQLINSERT=&quot;INSERT INTO tblSqlAdd (txtFirst, txtLast, txtColor) &quot;

set connupdate = server.createobject(&quot;ADODB.Connection&quot;)
connupdate.open &quot;TestAdd&quot;
connupdate.execute(SQLINSERT)
connupdate.close
set connupdate = nothing
%>

<html><head>
<title>SQL Add record example</title>
</head>
<body>
<% Response.Write &quot;Your record has been added&quot; %>
</body>
</html>

Any ideas as to what I'm doing wrong??? Thanks!!!
 
For one, you're using Request.QueryString instead of Request.Form since you're using the &quot;post&quot; method.

Second,
An insert statement's syntax is:
INSERT INTO table (column1,column2) VALUES ('value1','value2')
Adam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top