Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - ASP form write to DB issue

Reply
 
Old 11-24-2008   #1 (permalink)
avdvyver


 
 

ASP form write to DB issue

Hi,

I don't have much scripting experience and I need some help with a
simple piece of code. Basically, I have a html form with a input field
that posts the input to a ASP page (the ASP page must establish a
connection to a SQL database and write the input from the form to a
table). The content of the ASP page as follows:


' Declaring variables
Dim rest_nme, data_source, con, sql_insert

' Receiving values from Form
rest_nme = Request.Form("rest_nme")

data_source =
"Provider=SQLNCLI;Server=localhost;Database=RMS;Uid=user;Pwd=password;"
sql_insert = "insert into database.dbo.table (rest_nme) values ('" &
rest_nme & "')"

' Creating Connection Object and opening the database
Set con = CreateObject("ADODB.Connection")
con.Open data_source
con.Execute sql_insert

' Done. Close the connection
con.Close
Set con = Nothing

I know for a fact that the form input is passed to the ASP page
correctly (if I post the form to email the value is correct), but the
row thats being written to the SQL DB is empty. From the empty row
thats being written I must assume that the connection string works and
I have no idea where the issue might lie. Any suggestions would be
much appreciated!

My System SpecsSystem Spec
Old 11-24-2008   #2 (permalink)
mayayana


 
 

Re: ASP form write to DB issue

You might get an answer here but you'd
probably be better off asking in an ASP
group. This group is just for general VBS.
Quote:

>
> I don't have much scripting experience and I need some help with a
> simple piece of code. Basically, I have a html form with a input field
> that posts the input to a ASP page (the ASP page must establish a
> connection to a SQL database and write the input from the form to a
> table). The content of the ASP page as follows:
>
>
> ' Declaring variables
> Dim rest_nme, data_source, con, sql_insert
>
> ' Receiving values from Form
> rest_nme = Request.Form("rest_nme")
>
> data_source =
> "Provider=SQLNCLI;Server=localhost;Database=RMS;Uid=user;Pwd=password;"
> sql_insert = "insert into database.dbo.table (rest_nme) values ('" &
> rest_nme & "')"
>
> ' Creating Connection Object and opening the database
> Set con = CreateObject("ADODB.Connection")
> con.Open data_source
> con.Execute sql_insert
>
> ' Done. Close the connection
> con.Close
> Set con = Nothing
>
> I know for a fact that the form input is passed to the ASP page
> correctly (if I post the form to email the value is correct), but the
> row thats being written to the SQL DB is empty. From the empty row
> thats being written I must assume that the connection string works and
> I have no idea where the issue might lie. Any suggestions would be
> much appreciated!

My System SpecsSystem Spec
Old 11-24-2008   #3 (permalink)
Tim Williams


 
 

Re: ASP form write to DB issue

Do a response.write with the SQL and try running that using whatever tool
comes with the DB.

Tim

<avdvyver@xxxxxx> wrote in message
news:9d138a9a-0386-43d7-9f1c-ad95c7ceedba@xxxxxx
Quote:

> Hi,
>
> I don't have much scripting experience and I need some help with a
> simple piece of code. Basically, I have a html form with a input field
> that posts the input to a ASP page (the ASP page must establish a
> connection to a SQL database and write the input from the form to a
> table). The content of the ASP page as follows:
>
>
> ' Declaring variables
> Dim rest_nme, data_source, con, sql_insert
>
> ' Receiving values from Form
> rest_nme = Request.Form("rest_nme")
>
> data_source =
> "Provider=SQLNCLI;Server=localhost;Database=RMS;Uid=user;Pwd=password;"
> sql_insert = "insert into database.dbo.table (rest_nme) values ('" &
> rest_nme & "')"
>
> ' Creating Connection Object and opening the database
> Set con = CreateObject("ADODB.Connection")
> con.Open data_source
> con.Execute sql_insert
>
> ' Done. Close the connection
> con.Close
> Set con = Nothing
>
> I know for a fact that the form input is passed to the ASP page
> correctly (if I post the form to email the value is correct), but the
> row thats being written to the SQL DB is empty. From the empty row
> thats being written I must assume that the connection string works and
> I have no idea where the issue might lie. Any suggestions would be
> much appreciated!

My System SpecsSystem Spec
Old 11-25-2008   #4 (permalink)
trading_jacks


 
 

Re: ASP form write to DB issue

On Nov 24, 2:04*pm, avdvy...@xxxxxx wrote:
Quote:

> Hi,
>
> I don't have much scripting experience and I need some help with a
> simple piece of code. Basically, I have a html form with a input field
> that posts the input to a ASP page (the ASP page must establish a
> connection to a SQL database and write the input from the form to a
> table). The content of the ASP page as follows:
>
> ' Declaring variables
> Dim rest_nme, data_source, con, sql_insert
>
> ' Receiving values from Form
> rest_nme = Request.Form("rest_nme")
>
> data_source =
> "Provider=SQLNCLI;Server=localhost;Database=RMS;Uid=user;Pwd=password;"
> sql_insert = "insert into database.dbo.table (rest_nme) values ('" &
> rest_nme & "')"
>
> ' Creating Connection Object and opening the database
> Set con = CreateObject("ADODB.Connection")
> con.Open data_source
> con.Execute sql_insert
>
> ' Done. Close the connection
> con.Close
> Set con = Nothing
>
> I know for a fact that the form input is passed to the ASP page
> correctly (if I post the form to email the value is correct), but the
> row thats being written to the SQL DB is empty. From the empty row
> thats being written I must assume that the connection string works and
> I have no idea where the issue might lie. Any suggestions would be
> much appreciated!
Try hard coding your sql statement like below and see if the data is
written:

sql_insert = "insert into database.dbo.table (rest_nme) values
('"mydata"')"

Check your quotes - escape double quotes with single quotes as shown
above and below. Also check if you need the entire database.dbo.table
- you might just need table. Below is my exact insert string from an
app I wrote. This was using an access database, so it might be
slightly different.

StrSQL = "INSERT INTO verify ([name], [training], [ip], [user]) VALUES
('" & tName & "','" & tTraining & "','" & tIP & "','" & tUser & "')"

Just keep at it... something will get it clicking.
My System SpecsSystem Spec
Old 11-25-2008   #5 (permalink)
Bob Barrows


 
 

Re: ASP form write to DB issue

avdvyver@xxxxxx wrote:
Quote:

> Hi,
>
> I don't have much scripting experience and I need some help with a
> simple piece of code. Basically, I have a html form with a input field
> that posts the input to a ASP page (the ASP page must establish a
> connection to a SQL database and write the input from the form to a
> table). The content of the ASP page as follows:
>
>
> ' Declaring variables
> Dim rest_nme, data_source, con, sql_insert
>
> ' Receiving values from Form
> rest_nme = Request.Form("rest_nme")
>
> data_source =
>
"Provider=SQLNCLI;Server=localhost;Database=RMS;Uid=user;Pwd=password;"
Quote:

> sql_insert = "insert into database.dbo.table (rest_nme) values ('" &
> rest_nme & "')"
Change this to:
sql_insert = "insert into database.dbo.table (rest_nme) values (?)"

Quote:

>
> ' Creating Connection Object and opening the database
> Set con = CreateObject("ADODB.Connection")
> con.Open data_source
Create a command object:
Set cmd = CreateObject("ADODB.Command")
cmd.commandtext=sql_insert
cmd.commandtype = 1 '1=adCmdText
set cmd.activeconnection=con
cmd.execute ,rest_nme, 128 '128=adExecuteNoRecords

Quote:

> ' Done. Close the connection
> con.Close
> Set con = Nothing
>
If you need to pass more than one parameter value, you need to use a
variant array. See this message for more info:

Your use of dynamic sql is leaving you vulnerable to hackers using sql
injection:
http://mvp.unixwiz.net/techtips/sql-injection.html
http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23

See here for a better, more secure way to execute your queries by using
parameter markers (tokens):
http://groups-beta.google.com/group/...e36562fee7804e

Personally, I prefer using stored procedures
http://groups.google.com/group/micro...09dc1701?hl=en


http://groups.google.com/groups?hl=e...tngp13.phx.gbl

http://groups.google.com/groups?hl=e...TNGP11.phx.gbl

http://www.google.com/groups?selm=eE...&output=gplain

http://www.google.com/groups?hl=en&l...TNGP12.phx.gbl

Using Command object:
http://groups-beta.google.com/group/...e36562fee7804e


--
HTH,
Bob Barrows


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Cannot write to drive "Media is write protected" Vista hardware & devices
how to get powershell to write to event log or write a log file? PowerShell
Write-Error doesn't write anyting PowerShell
The disk is write-protected. Remove the write-protection or... Vista General
newline in Write-Debug or Write-Verbose PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46