Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Please Help! ASP form to SQL database

Author  Topic 

Beowulf
Starting Member

2 Posts

Posted - 2008-04-25 : 11:02:53
I'm using SQL server on godaddy.com, and for the life of me, tried all freakin day yesterday to get a form to send data to my table, and can't get it to work for the life of me

I think the asp form sends the information to the asp page that is to add the information to the tables correctly, but am not entirely sure, so here is the code for the form:

<html>
<head>
<title>Form Entry</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><form method="post" action="add.asp">
<table>
<tr>
<td>CustomerID:</td>
<td><input name="CustID"></td>
</tr><tr>
<td>Company Name:</td>
<td><input name="Company"></td>
</tr><tr>
<td>Contact Name:</td>
<td><input name="Contact"></td>
</tr><tr>
<td>Address1:</td>
<td><input name="Address1"></td>
</tr><tr>
<td>Address2:</td>
<td><input name="Address2"></td>
</tr><tr>
<td>Address3:</td>
<td><input name="Address3"></td>
</tr><tr>
<td>City:</td>
<td><input name="City"></td>
</tr><tr>
<td>State:</td>
<td><input name="State"></td>
</tr><tr>
<td>Zip:</td>
<td><input name="Zip"></td>
</tr>
<td>Email:</td>
<td><input name="Email"></td>
</tr><tr>
<td>Phone:</td>
<td><input name="Phone"></td>
</tr>
</table>
<br /><br />
<input type="submit" value="Add New">
<input type="reset" value="Cancel">
</form>
</body>
</html>


Now for the page that is giving me the problem (I think). I'm pretty sure I'm fudging up the connectivity somewhere because all I get is an http 500 error every time I try to upload the information.

Why won't it bloody connect?!?!

Also, is the DIM function on this page used to hide important information? If you guys can help me fix this, I'd be incredibly, incredibly greatful, I'm frustrated out of my mind!

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="CP_ACP"%>
<html>
<head>
<title>piece of shit page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<%
Dim oConn, oRs
Dim qry, connectstr
Dim db_name, db_username, db_userpassword
Dim db_server

db_server = "whsql-v22.prod.mesa1.secureserver.net"
db_name = "Fulfillment"
db_username = "Fulfillment"
db_userpassword = "your_password"
tablename = "KSEP_Customers"

connectstr = "Driver={SQL Server};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_username & ";PWD=" & db_userpassword

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"sql="INSERT INTO customers (CustID,companyname,"
sql=sql & "contactname,address,city,postalcode,country)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("CustID") & "',"
sql=sql & "'" & Request.Form("Company") & "',"
sql=sql & "'" & Request.Form("Contact") & "',"
sql=sql & "'" & Request.Form("Address1") & "',"
sql=sql & "'" & Request.Form("Address2") & "',"
sql=sql & "'" & Request.Form("Address3") & "',"
sql=sql & "'" & Request.Form("City") & "',"
sql=sql & "'" & Request.Form("State") & "',"
sql=sql & "'" & Request.Form("Zip") & "',"
sql=sql & "'" & Request.Form("Email") & "',"
sql=sql & "'" & Request.Form("Phone") & "')"on error resume next
conn.Execute sql,recaffected
if err<>0 then
Response.Write("No update permissions!")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
%>

</body>
</html>

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-25 : 11:07:43
The connection SHOULD not open the database file directly...

See http://www.connectionstrings.com/?carrier=access2007

conn.connectionstring = "......"
conn.open


Also see
http://support.microsoft.com/kb/168336



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-25 : 11:08:16
And while you are reading, also read about SQL injection.

ALWAYS USE PARAMETRIZED calls to the databas...



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Beowulf
Starting Member

2 Posts

Posted - 2008-04-25 : 11:36:50
Can you please alter my script for me so I can see what you are talking about? I have absoultely no idea what I'm doing. Thanks,

Beowulf :)
Go to Top of Page

uberman
Posting Yak Master

159 Posts

Posted - 2008-04-25 : 12:01:08
DIM is used to declare variables in vbscript in Classic ASP. It is a good thing... although I notice that the <@ language directive is for Javascript and DIM is a vbscript directive i think ... In fact looking at it I think the sql is the least of your worries, the first thing I'd do is take the @ directive out and then start again as the code looks vb not js to me

Then

You set up connnectstr but don't use it. You are using conn which is an ACCESS mdb file that (should be) on the local drive (c:/webdata/northwind.mdb)
Go to Top of Page
   

- Advertisement -