Skip to main content
Inspiring
August 28, 2006
Question

how to "run" an INSERT command? ASP/VB

  • August 28, 2006
  • 6 replies
  • 569 views
Hi.

I have created an INSERT command in the Server Behaviours panel and I want
to know how I can trigger it?
At the moment, my ASP page just loads and nothing is inserted into the
database.

I would like to trigger the INSERT command when a form button, a form
unrelated to the INSERT command, is clicked.

I have trawled Google for hours and just can't find any advice on this!

Thanks in advance for any help offered.
Nath.


This topic has been closed for replies.

6 replies

Angell EYE
Inspiring
August 29, 2006
Are you using the most current version of WA eCart? Are you absolutely sure that you got everything binded correctly in the Add Cart to Database behaviors? There's actually 2 behaviors that go together..sounds like you might be leaving out the first one.

First, you use the Store Cart Summary behavior to put in the customer name, billing address, etc. This creates the invoice and stores the new invoiceID into a session variable for use in the next part.

Then you use the Store Cart Details behavior to insert the cart contents. You have to include the name you chose for the invoiceID's session variable so that it can add the cart contents to the correct invoice.

In the end you'd have an invoice with both Summary and Details so it would include all the user's information as well as the purchase (products) details.

WA eCart has worked great for me. The only troubles I've ever had was not binding things correctly. Double check all of that and make sure you're running both behaviors and not just the Store Details one.
Inspiring
August 29, 2006
Hi again.
From what I'm reading Angell, the code is more complex in order to prevent
SQL Injection so, whilst your code might work, it is vulnerable.
I have bought Studio, so I think I'd like to get the most out of it and, if
that includes having to add these extra lines of code, for increased
security, then so be it....ahem, except it doesn't work!! :o)

By the way, there is no documentation in the DW help files for DW8.0.2!!
Just discovered this and am, frankly, very annoyed with Adobe about it.
The screen shots in the help are from DW8 and don't relate to DW8.0.2.
Thanks a bunch Adobe!!

Going out of my mind with this though. No documentation from Adobe to help
me create the SQL INSERT Command, no UK support from WebAssist (unless you
like working through the night), and none of the functions/behaviours
working from either company....what are we supposed to do now?

I appreciate your help Angell, thank you. If you've any ideas on the
WebAssist Save Cart to Database behaviour I sure would appreciate it.

Thanks
Nath.

"Angell EYE" <webforumsuser@macromedia.com> wrote in message
news:ed1hef$hco$1@forums.macromedia.com...
> Yeah DW can get pretty sloppy with some of it's code sometimes. It types
> out a
> lot more than you really need to make a command insert/update work. What
> I
> have there is what I use all the time in place of DW's tools and it works
> great
> and saves me many lines of code.
>
>
> The first problem you have is that you left the line
>
> SaveOrder.ActiveConnection = MM_connNAME_STRING
>
> That MM_connName_STRING needs to be changed to the name of the connection
> you're actually using. That will probably fix your problem as right now
> it
> doesn't know what database to connect to.
>
> I really have no idea what all of that Paramaters stuff is. I've never
> used
> anything like that before. In fact, it looks like you're using WebAssist
> shopping cart which is the same thing I use and I've still never seen a
> setup
> like you've got here.
>
> Again, though, just change the connection name to your actual connection
> and
> you should be good if the software wrote out all that stuff for you.
>


Inspiring
August 29, 2006
Hi,

On this page I have an include file which contains my connection string, so
I think I SHOULD have this line:
SaveOrder.ActiveConnection = MM_connNAME_STRING

The problem I'm having is that Dreamweaver asked me for a "type" and "size"
for each field and I just didn't know what to enter! Oh, and there's
NOTHING in the help about it. <sigh>
To be honest, for the �750 I paid for "Studio", I was hoping that an INSERT
would, at least, work!

I'm just trying to INSERT some of the WA_eCart data to the database, along
with the user data, so it isn't a WA_eCart behaviour or anything which is
why you probably don't recognise it.
You've reminded me of the WA Add to Database behaviour though! :o)

<some time later>....Ah, just tried that and it is saving everything to the
database, but not the user information (taken from hidden form fields on the
page). Any idea why it wouldn't be saving that data? I'm not getting an
error, and the cart details are saving ok...here's my WA eCart Store Cart
Details code:

<%' WA eCart Store Cart Details in Db
if (cStr(Request.Form("checkoutbtn.x")) <> "") then
WA_connection = MM_connNAME_STRING
WA_table = "dbo.tblpaidorders"
WA_redirectURL = ""
WA_indexField = "orderID"
WA_fieldNamesStr =
"orderID|firstnames|surname|businessname|billaddress|billaddress1|billaddress2|billregion|billcountry|billpostcode|billtelephoneday|billmobile|billtelephoneeve|billemail|customerID|orderitem|deliverytime|vanopname|vanopID|orderprice|ordertotal"
WA_fieldValuesStr = "" & cStr(WA_eCart_DisplayInfo(MYeCart, "ID")) & "" &
"|" & "" & cStr(Request.Form("firstnames")) & "" & "|" & "" &
cStr(Request.Form("surname")) & "" & "|" & "" &
cStr(Request.Form("billbusiness")) & "" & "|" & "" &
cStr(Request.Form("billaddress")) & "" & "|" & "" &
cStr(Request.Form("billaddress1")) & "" & "|" & "" &
cStr(Request.Form("billaddress2")) & "" & "|" & "" &
cStr(Request.Form("regionID")) & "" & "|" & "" &
cStr(Request.Form("billcountry")) & "" & "|" & "" &
cStr(Request.Form("billpostcode")) & "" & "|" & "" &
cStr(Request.Form("billtelephoneday")) & "" & "|" & "" &
cStr(Request.Form("billmobile")) & "" & "|" & "" &
cStr(Request.Form("billtelephoneeve")) & "" & "|" & "" &
cStr(Request.Form("billemail")) & "" & "|" & "" &
cStr(WA_eCart_DisplayInfo(MYeCart, "CustID")) & "" & "|" & "" &
cStr(WA_eCart_DisplayInfo(MYeCart, "Name")) & "" & "|" & "" &
cStr(WA_eCart_DisplayInfo(MYeCart, "Description")) & "" & "|" & "" &
cStr(WA_eCart_DisplayInfo(MYeCart, "VanOpInit")) & "" & "|" & "" &
cStr(WA_eCart_DisplayInfo(MYeCart, "VanOpID")) & "" & "|" & "" &
cStr(WA_eCart_DisplayInfo(MYeCart, "TotalPrice")) & "" & "|" & "" &
cStr(WA_eCart_GrandTotal(MYeCart)) & ""
WA_columnTypesStr =
"none,none,NULL|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|none,none,NULL|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|none,none,NULL|',none,''|',none,''|',none,''|none,none,NULL|none,none,NULL|none,none,NULL"
indexFieldIndex = -1
WA_fieldValues = Split(WA_fieldValuesStr,"|")
if (WA_redirectURL <> "" AND Request.QueryString <> "" AND
Request.QueryString.Count > 0) then
if (inStr(WA_redirectURL,"?") > 0) then
WA_redirectURL = WA_redirectURL & "&"
else
WA_redirectURL = WA_redirectURL & "?"
end if
WA_redirectURL = WA_redirectURL & Request.QueryString
end if
WA_cmdObjString = "ADODB.Command"
set WA_editCmd = Server.CreateObject(WA_cmdObjString)
WA_editCmd.ActiveConnection = WA_connection
WA_fieldNames = Split(WA_fieldNamesStr,"|")
WA_columns = Split(WA_columnTypesStr,"|")
for i = 0 to Ubound(WA_fieldNames)
if (WA_indexField = WA_fieldNames(i)) then
indexFieldIndex = i
exit for
end if
next
deleteFieldValue = cStr(WA_fieldValues(indexFieldIndex))
if (deleteFieldValue <> "" AND deleteFieldValue <> "undefined") then
deleteParamsObj = WA_generateInsertParams(Array(WA_indexField),
Array(WA_columns(indexFieldIndex)), Array(deleteFieldValue), -1)
WA_editCmd.CommandText = "Delete from " & WA_table & " where " &
WA_indexField & " = " & deleteParamsObj(2)
WA_editCmd.Execute()
end if
set MYeCart = WA_eCart_MoveFirst(MYeCart)
while (NOT WA_eCart_EOF(MYeCart))
WA_fieldValuesStr = "" & cStr(WA_eCart_DisplayInfo(MYeCart, "ID")) & ""
& "|" & "" & cStr(Request.Form("firstnames")) & "" & "|" & "" &
cStr(Request.Form("surname")) & "" & "|" & "" &
cStr(Request.Form("billbusiness")) & "" & "|" & "" &
cStr(Request.Form("billaddress")) & "" & "|" & "" &
cStr(Request.Form("billaddress1")) & "" & "|" & "" &
cStr(Request.Form("billaddress2")) & "" & "|" & "" &
cStr(Request.Form("regionID")) & "" & "|" & "" &
cStr(Request.Form("billcountry")) & "" & "|" & "" &
cStr(Request.Form("billpostcode")) & "" & "|" & "" &
cStr(Request.Form("billtelephoneday")) & "" & "|" & "" &
cStr(Request.Form("billmobile")) & "" & "|" & "" &
cStr(Request.Form("billtelephoneeve")) & "" & "|" & "" &
cStr(Request.Form("billemail")) & "" & "|" & "" &
cStr(WA_eCart_DisplayInfo(MYeCart, "CustID")) & "" & "|" & "" &
cStr(WA_eCart_DisplayInfo(MYeCart, "Name")) & "" & "|" & "" &
cStr(WA_eCart_DisplayInfo(MYeCart, "Description")) & "" & "|" & "" &
cStr(WA_eCart_DisplayInfo(MYeCart, "VanOpInit")) & "" & "|" & "" &
cStr(WA_eCart_DisplayInfo(MYeCart, "VanOpID")) & "" & "|" & "" &
cStr(WA_eCart_DisplayInfo(MYeCart, "TotalPrice")) & "" & "|" & "" &
cStr(WA_eCart_GrandTotal(MYeCart)) & ""
WA_fieldValues = Split(WA_fieldValuesStr,"|")
insertParamsObj = WA_generateInsertParams(WA_fieldNames, WA_columns,
WA_fieldValues, -1)
WA_editCmd.CommandText = "insert into " & WA_table & " (" &
insertParamsObj(1) & ") values (" & insertParamsObj(2) & ")"
WA_editCmd.Execute()
set MYeCart = WA_eCart_MoveNext(MYeCart)
wend
set MYeCart = WA_eCart_MoveFirst(MYeCart)
WA_editCmd.ActiveConnection.Close()
if (WA_redirectURL <> "") then
Response.Redirect(WA_redirectURL)
end if
end if
%>

Thanks again Angell...really appreciate it.
Regards
Nath.

"Angell EYE" <webforumsuser@macromedia.com> wrote in message
news:ed1hef$hco$1@forums.macromedia.com...
> Yeah DW can get pretty sloppy with some of it's code sometimes. It types
> out a
> lot more than you really need to make a command insert/update work. What
> I
> have there is what I use all the time in place of DW's tools and it works
> great
> and saves me many lines of code.
>
>
> The first problem you have is that you left the line
>
> SaveOrder.ActiveConnection = MM_connNAME_STRING
>
> That MM_connName_STRING needs to be changed to the name of the connection
> you're actually using. That will probably fix your problem as right now
> it
> doesn't know what database to connect to.
>
> I really have no idea what all of that Paramaters stuff is. I've never
> used
> anything like that before. In fact, it looks like you're using WebAssist
> shopping cart which is the same thing I use and I've still never seen a
> setup
> like you've got here.
>
> Again, though, just change the connection name to your actual connection
> and
> you should be good if the software wrote out all that stuff for you.
>


Angell EYE
Inspiring
August 29, 2006
Yeah DW can get pretty sloppy with some of it's code sometimes. It types out a lot more than you really need to make a command insert/update work. What I have there is what I use all the time in place of DW's tools and it works great and saves me many lines of code.


The first problem you have is that you left the line

SaveOrder.ActiveConnection = MM_connNAME_STRING

That MM_connName_STRING needs to be changed to the name of the connection you're actually using. That will probably fix your problem as right now it doesn't know what database to connect to.

I really have no idea what all of that Paramaters stuff is. I've never used anything like that before. In fact, it looks like you're using WebAssist shopping cart which is the same thing I use and I've still never seen a setup like you've got here.

Again, though, just change the connection name to your actual connection and you should be good if the software wrote out all that stuff for you.
Inspiring
August 29, 2006
Hi Angell,
Thank you for the support.
I've added the If/End If as you've instructed although, in DW8, my INSERT
command code looks very different to what you've listed as an example.
Here's what I've got now:

<%
If Request.Form("Submit") <> "" Then
Set SaveOrder = Server.CreateObject ("ADODB.Command")
SaveOrder.ActiveConnection = MM_connNAME_STRING
SaveOrder.CommandText = "INSERT INTO dbo.tblpaidorders (orderID, firstnames,
surname, businessname, billaddress, billaddress1, billaddress2, billregion,
billcountry, billpostcode, billtelephoneday, billmobile, billtelephoneeve,
billemail, customerID, orderitem, deliverytime, vanopname, vanopID,
orderprice, ordertotal, orderstatus, statusdetails, VPSTxID, TXAuthNo)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARorderID", 3, 1,
30, MM_IIF(WA_eCart_DisplayInfo(MYeCart), WA_eCart_DisplayInfo(MYeCart),
SaveOrder__VARorderID & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARfirstnames", 200,
1, 150, MM_IIF(Request.Form("firstnames"), Request.Form("firstnames"),
SaveOrder__VARfirstnames & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARsurname", 200, 1,
100, MM_IIF(Request.Form("surname"), Request.Form("surname"),
SaveOrder__VARsurname & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARbusinessname",
200, 1, 200, MM_IIF(Request.Form("businessname"),
Request.Form("businessname"), SaveOrder__VARbusinessname & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARbilladdress", 200,
1, 100, MM_IIF(Request.Form("billaddress"), Request.Form("billaddress"),
SaveOrder__VARbilladdress & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARbilladdress1",
200, 1, 100, MM_IIF(Request.Form("billaddress1"),
Request.Form("billaddress1"), SaveOrder__VARbilladdress1 & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARbilladdress2",
200, 1, 100, MM_IIF(Request.Form("billaddress2"),
Request.Form("billaddress2"), SaveOrder__VARbilladdress2 & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARbillregion", 3, 1,
3, MM_IIF(Request.Form("billregion"), Request.Form("billregion"),
SaveOrder__VARbillregion & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARbillcountry", 200,
1, 50, MM_IIF(Request.Form("billbountry"), Request.Form("billbountry"),
SaveOrder__VARbillcountry & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARbillpostcode",
200, 1, 30, MM_IIF(Request.Form("billpostcode"),
Request.Form("billpostcode"), SaveOrder__VARbillpostcode & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARbilltelephoneday",
200, 1, 100, MM_IIF(Request.Form("billtelephoneday"),
Request.Form("billtelephoneday"), SaveOrder__VARbilltelephoneday & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARbillmobile", 200,
1, 100, MM_IIF(Request.Form("billmobile"), Request.Form("billmobile"),
SaveOrder__VARbillmobile & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARbilltelephoneeve",
200, 1, 100, MM_IIF(Request.Form("billtelephoneeve"),
Request.Form("billtelephoneeve"), SaveOrder__VARbilltelephoneeve & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARbillemail", 200,
1, 200, MM_IIF(Request.Form("billemail"), Request.Form("billemail"),
SaveOrder__VARbillemail & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARcustomerID", 3, 1,
30, MM_IIF(WA_eCart_DisplayInfo(MYeCart), WA_eCart_DisplayInfo(MYeCart),
SaveOrder__VARcustomerID & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARorderitem", 200,
1, 255, MM_IIF(WA_eCart_DisplayInfo(MYeCart), WA_eCart_DisplayInfo(MYeCart),
SaveOrder__VARorderitem & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARdeliverytime",
200, 1, 100, MM_IIF(WA_eCart_DisplayInfo(MYeCart),
WA_eCart_DisplayInfo(MYeCart), SaveOrder__VARdeliverytime & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARvanopname", 200,
1, 6, MM_IIF(WA_eCart_DisplayInfo(MYeCart), WA_eCart_DisplayInfo(MYeCart),
SaveOrder__VARvanopname & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARvanopID", 3, 1,
30, MM_IIF(WA_eCart_DisplayInfo(MYeCart), WA_eCart_DisplayInfo(MYeCart),
SaveOrder__VARvanopID & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARorderprice", 3, 1,
30, MM_IIF(WA_eCart_DisplayInfo(MYeCart), WA_eCart_DisplayInfo(MYeCart),
SaveOrder__VARorderprice & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARordertotal", 3, 1,
30, MM_IIF(WA_eCart_GrandTotal(MYeCart), WA_eCart_GrandTotal(MYeCart),
SaveOrder__VARordertotal & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARorderstatus", 200,
1, 50, MM_IIF(Request.Form("orderstatus"), Request.Form("orderstatus"),
SaveOrder__VARorderstatus & ""))
SaveOrder.Parameters.Append SaveOrder.CreateParameter("VARstatusdetails",
200, 1, 200, MM_IIF(Request.Form("statusdetails"),
Request.Form("statusdetails"), SaveOrder__VARstatusdetails & ""))
SaveOrder.CommandType = 1
SaveOrder.CommandTimeout = 0
SaveOrder.Prepared = true
SaveOrder.Execute()
End If
%>

When I open this page, and click the submit button (which transfers me off
to the Payment Service Provider's pages), I am NOT receiving an error and
everything seems fine....except it isn't saving anything to the database?
That;s got me really confused because I'd at least expect an error of some
kind.

Also, when reading the DW8 tutorial on creating an INSERT command there is
no reference to having to specify "type" and "size" for each field however,
when I created mine, it simply wouldn't let me create it unless I specified
type and size for each field. That is frustrating, I have to say, because
I'd expect the "Help" to cover things like this. Thank goodness the forums
exist.
Anyway, I just don't have a clue what I should be entering for "type" and
"size" so, no doubt, this is where my problem lies. For example, what
"size" should I specify for my "int" fields?

If you can see anything immediately wrong with this, that would cause it NOT
to save the data to database, then I'd appreciate your advice. Thanks.

Regards
Nath.

"Angell EYE" <webforumsuser@macromedia.com> wrote in message
news:ecv8ls$q8k$1@forums.macromedia.com...
> Here's a basic setup for an INSERT with ASP
>
> SQL = "INSERT INTO TableName (field_names) VALUES (field_values)
>
> set insertInvoice = Server.CreateObject("ADODB.Command")
> insertInvoice.ActiveConnection = MM_connName_STRING
> insertInvoice.CommandText = SQL
> insertInvoice.CommandType = 1
> insertInvoice.CommandTimeout = 0
> insertInvoice.Prepared = true
> insertInvoice.Execute()
> set insertInvoice = Nothing
>
> If you wanted this to run when you submitted a form you would place it
> within
> an If statement.
>
> If Request.Form("Submit") <> "" Then
> set insertInvoice = Server.CreateObject("ADODB.Command")
> insertInvoice.ActiveConnection = MM_connName_STRING
> insertInvoice.CommandText = SQL
> insertInvoice.CommandType = 1
> insertInvoice.CommandTimeout = 0
> insertInvoice.Prepared = true
> insertInvoice.Execute()
> set insertInvoice = Nothing
> End If
>


Angell EYE
Inspiring
August 28, 2006
Here's a basic setup for an INSERT with ASP

SQL = "INSERT INTO TableName (field_names) VALUES (field_values)

set insertInvoice = Server.CreateObject("ADODB.Command")
insertInvoice.ActiveConnection = MM_connName_STRING
insertInvoice.CommandText = SQL
insertInvoice.CommandType = 1
insertInvoice.CommandTimeout = 0
insertInvoice.Prepared = true
insertInvoice.Execute()
set insertInvoice = Nothing

If you wanted this to run when you submitted a form you would place it within an If statement.

If Request.Form("Submit") <> "" Then
set insertInvoice = Server.CreateObject("ADODB.Command")
insertInvoice.ActiveConnection = MM_connName_STRING
insertInvoice.CommandText = SQL
insertInvoice.CommandType = 1
insertInvoice.CommandTimeout = 0
insertInvoice.Prepared = true
insertInvoice.Execute()
set insertInvoice = Nothing
End If