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

Asp Form

Status
Not open for further replies.

Newbie311

Programmer
Oct 6, 2003
30
0
0
GB
Heres an easy 1!I need a simple ASP form to insert values into a database. The form may consist of only two text boxes. Could anyone point me in the direction of where i may find this or provide me with some simple code to do this?
 
try this, all this code requires is your connection string

name is file insert.asp
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
if request("submit")="Add Record" then
'assuming connstr is your connection string
set conn=CreateObject("ADODB.Connection")
conn.open(connstr)
sql="insert into tblname (field1,field2) values ('"&request("text1")&"','"&request("text2")&"')"
conn.execute(sql)
conn.close
set conn=nothing
response.redirect("thankyou.asp")
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Insert Record</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="insert.asp">
  
  <p>
    <input name="text2" type="text" >
  </p>
  <p>
    <input name="text2" type="text">
</p>
  <p>
    <input type="submit" name="Submit" value="Add Record">
</p>
</form>
</body>
</html>
 
connstr="Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & dbasepathhere& ";"

or

connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=& dbasepathhere&";"
 
That piece of code doesn't seem to work.Im using an access database i altered the connection string to that of mine and i dont get any errors when the form submits however the data doesn't get put into the database?
Any ideas?
 
post your code so we can see what you have, also what error do you get
 
Hi Steven, I managed to fix that problem it occured because in your code you have named two text boxes the same.
I have now posted the current error which is related to the below query.

sql="insert into users(username,password) values('"&request("text1")&"','"&request("text2")&"')"

It gives me a syntax error,Im using an Access DB if that helps?
 
whats the error number, also try renaming the username field to uname. Im not sure but it might be a reserved word
 
sorry - noticed your question got answered in a different thread.

Please give stars to those you feel helped you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top