Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · Web Hosting Plans · Faisal Khan's Blog · Contact
Forums : ASP : ADO/ODBC : can't convert form to insert into SQL db. Signup · Login
Author Thread
can't convert form to insert into SQL db.
Posted in tutorial: Inserting Form content into Database with ASP
·  drdan
User
Joined: 29 Mar 2009
Total Posts: 2
can't convert form to insert into SQL db.
Posted: 29 Mar 2009
I ran your form "as is" and it worked fine. When I tried to modify to insert data into a SQL db, I got a HTTP 500 error. Here's my code:

<%
' Declaring variables
Dim company, address1, city, state, data_source, con, sql_insert

' A Function to check if some field entered by user is empty
Function ChkString(string)
If string = "" Then string = " "
ChkString = Replace(string, "'", "''")
End Function

' Receiving values from Form
name = ChkString(Request.Form("company"))
email = ChkString(Request.Form("address1"))
country = ChkString(Request.Form("city"))
comments = ChkString(Request.Form("state"))

data_source = "Provider=SQLOLEDB; Data Source=MYSERVER; Initial Catalog=CATALOG; User Id=ID; Password=password"
sql_insert = "insert into TABLE (company, address1, city, state) values ('" & _
company & "', '" & address1 & "', '" & city & "', '" & state & "')"

' Creating Connection Object and opening the database
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
con.Execute sql_insert
' Done. Close the connection
con.Close
Set con = Nothing
Response.Write "All records were successfully entered into the database."
%>


·  drdan
User
Joined: 29 Mar 2009
Total Posts: 2
inserting into db correction.
Posted: 29 Mar 2009
I did correct the receiving values...still doesn't work.

Users Subscribed To This Thread
drdan  

Users Who Have Visited This Thread In Last 24 Hours
8 Visitors

Login
UserName Or Email Address:       Password:       Auto-Login:    
· Create New User Account
· Send Forgotten Password by Email
 
© 1999 - 2009 Stardeveloper.com, All Rights Reserved.