Inserting data into a table

G

Geoff Wickens

I am quite new to all this but am trying to create a database driven site. I
have been able to use information from my sample database but I now want to
be able to insert data into it. At present I put the data into my local copy
of the access database and then upload it again to my server - not an ideal
solution!

I have tried using the INSERT command and it works fine if I enter the data
into the statement. What I really want to do is collect the data from a form
and then insert this into the database. My code is as follows:

Page for collecting the data:

<form name="useradd" method="post" action="testadd.asp">
<p>Username:
<input type="text" name="username">
</p>
<p>Password:
<input type="text" name="password">
</p>
<p> Category:
<select name="select">
<option>member</option>
<option>committee</option>
<option>admin</option>
<option>guest</option>
</select>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">
</p>
</form>


I then have the following code on the page (testadd.asp) to add this
information to my database.

<%
u = Request.Form("username")
p = Request.Form("password")
c = Request.Form("category")

Set Catalog=Server.CreateObject("ADODB.Recordset")
Catalog.open "INSERT INTO tbltest (username, password, category) VALUES (u ,
p, c)", "DSN=members"
%>

The thing which goes wrong is the VALUES part of the statement. It seems to
want 'u' etc but then puts in this text rather than the contents of my
variable.

Any help most welcome.

Geoff Wickens
 
O

only me

You forgot to reference the actual data itself

INSERT INTO tbltest (username, password, category)
VALUES (' " & u & " ',' " & p & " ',' " & c & " ')

note use of single quotes to delimit the text fields - I have put extra
space between single and double quote to be clear - you should remove other
wise your stored data will have leading and trailing space
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top