Newsgroup: it.comp.www.asp
Titolo: carrello e aggiornamento data base

ciao a tutti ragazzi vado al dunque..io ho realizzato un commerce  funziona
tutto bene fino a quando vado al passaggio finale ovvero al completamento
del form per raccogliere i dati del potenziale cliente (la cosa
principale..:-)))... gli ordini vengono regolarmente registrati nel database
(tab. baz_order_items) mentre i dati dei clienti no (tab. baz_orders). O
meglio i dati degli ordini dei prodotti vengono registrati sempre in un
nuovo record che si aggiunge agli altri esistenti man mano che ci sono
ordini nuovi, mentre i dati presi dal form del cliente vengono sempre
sovrascritti sul precedente. Ho notato che nella tabella dei datyi cliente
(baz_orders) l' "order_id" rimane sempre vuoto, o cmq non viene registrato.
a seguito i file interessati.
questo e' il file baz_order_review_action.asp
che registra gli ordini dei prodotti.
<%@ LANGUAGE="VBSCRIPT" %>
<!--#include virtual="/adovbs.inc"-->
<%
    set outpostDB = Server.CreateObject("ADODB.Connection")
    outpostDB.Open "outpost"
    if cstr(Session("order_id")) = "" then
%>
        <!--#include virtual="/pagetop.txt"-->
<%
        Response.Write "There is no current order.  If you had "
        Response.Write "previously added items to your order, "
        Response.Write "your session may have timed out."
        Response.Write "<P>"
%>
        <!--#include file="baz_search.inc"-->
        <!--#include virtual="/pagebottom.txt"-->
        </BODY>
        </HTML>
<%    else
        p_order_id = cstr(Session("order_id"))
        set prodSet = Server.CreateObject("ADODB.RecordSet")
        prodSet.Open "select * from baz_order_items " _
            & "where order_id="& p_order_id, _
            outpostDB, adOpenDynamic, adLockPessimistic, adCmdText
        while not prodSet.EOF
            p_element = "quant" & prodSet("prod_id")
            p_quant = Request.form(p_element)
            if p_quant <> "" and isNumeric(p_quant) then
                if p_quant = 0 then
                    prodSet.Delete
                else
                    prodSet("quantity") = p_quant
                end if
            end if
            prodSet.Update
            prodSet.MoveNext
        wend
         if Request.form("p_button") = "Update Totals" then
             prodSet.Close
             set prodSet = Nothing
             outpostDB.Close
             set outpostDB = Nothing
             Server.Transfer "/bazaar/baz_order_review.asp"
         else
 %>
             <!--#include virtual="/pagetop.txt"-->
             <H2>Your Order</H2>
             Is something incorrect?  Feel free to
             <A HREF="baz_order_review.asp">change your order</A>.
             <P>
             <FORM ACTION="baz_order_complete_action.asp"
                 METHOD="post">
             <INPUT TYPE="hidden" NAME="p_order_id"
                 VALUE="<%=p_order_id%>">
             <TABLE border=1>
             <TR>
                 <TH>Quantity</TH>
                 <TH>Prod. #</TH>
                 <TH>Description</TH>
                 <TH>Unit Price</TH>
                 <TH>Ext. Price</TH>
             </TR>
 <%
             set prodInfoSet = Server.CreateObject("ADODB.RecordSet")
             prodInfoSet.Open "baz_products", outpostDB, _
                 adOpenStatic, adLockOptimistic, adCmdTable
             p_total = 0
             prodSet.MoveFirst
             while not prodSet.EOF
                 prodInfoSet.MoveFirst
                 prodInfoSet.Find "prod_id = " & prodSet("prod_id")
                 p_prod_id = prodSet("prod_id")
                 p_prod_name = prodInfoSet("prod_name")
                 p_price = formatNumber(prodInfoSet("prod_price"), 2)
                 p_quant = prodSet("quantity")
                 p_extprice = formatNumber((p_price * p_quant), 2)
                 p_total = p_total + p_extprice
 %>
                 <TR>
                     <TD><%= p_quant %></TD>
                     <TD><%= p_prod_id %></TD>
                     <TD><%= p_prod_name %></TD>
                     <TD ALIGN="right">$<%= p_price %></TD>
                     <TD ALIGN="right">$<%= p_extprice %></TD>
                 </TR>
                 <INPUT TYPE="hidden" NAME="p_orderitem"
                    VALUE="<%=p_prod_id%>,<%=p_quant%>">
<%
                prodSet.MoveNext
            wend
%>
            <TR>
                <TD COLSPAN = 4> Subtotal:</TD>
                <TD ALIGN=right>
                    $<%= formatNumber(p_total, 2) %>
                </TD>
            </TR>
            <TR>
                <TD COLSPAN = 4> Shipping (5%):</TD>
                <TD ALIGN=right>
                    $<%= formatNumber((p_total*.05), 2) %>
                    <INPUT TYPE="hidden" NAME="p_shipping"
                        VALUE="<%=p_total*.05%>">
                </TD>
            </TR>
            <TR>
                <TD COLSPAN = 4> Total:</TD>
                <TD ALIGN=right>
                    $<%= formatNumber((p_total*1.05), 2) %>
                    <INPUT TYPE="hidden" NAME="p_total"
                        VALUE="<%=p_total%>">
                </TD>
            </TR>
            </TABLE>
            <P>
            <H3>Payment Information</H3>
            <TABLE>
            <TR>
                <TD>Name:</TD>
                <TD>
                <INPUT TYPE="text" NAME="p_first" SIZE="10">
                <INPUT TYPE="text" NAME="p_last" SIZE="10">
                </TD>
            </TR>
            <TR>
                <TD>Address:</TD>
                <TD>
                <INPUT TYPE="text" NAME="p_address1" SIZE=21>
                </TD>
            </TR>
            <TR>
                <TD>Address:</TD>
                <TD>
                <INPUT TYPE="text" NAME="p_address2" SIZE=21>
                </TD>
            </TR>
            <TR>
                <TD>City, State, Postal Code: </TD>
                <TD>
                <INPUT TYPE="text" NAME="p_city" SIZE=10>
                <INPUT TYPE="text" NAME="p_state" SIZE=5>
                <INPUT TYPE="text" NAME="p_postalcode" SIZE=5>
                </TD>
            </TR>
            <TR>
                <TD>Country: </TD>
                <TD>
                <INPUT TYPE="text" NAME="p_country" SIZE=21>
                </TD>
            </TR>
            <TR>
                <TD>Telephone: </TD>
                <TD>
                <INPUT TYPE="text" NAME="p_phone" SIZE=21>
                </TD>
            </TR>
            <TR>
                <TD COLSPAN=2>
                <hr>
                <INPUT TYPE="radio" NAME="p_cc_type" VALUE="MC">
                MasterCard
                <INPUT TYPE="radio" NAME="p_cc_type" VALUE="V">
                Visa
                <INPUT TYPE="radio" NAME="p_cc_type" VALUE="AMEX">
                American Express
                </TD>
            </TR>
            <TR>
                <TD>Card Number: </TD>
                <TD>
                <INPUT TYPE="text" NAME="p_cc_number" SIZE=21>
                </TD>
            </TR>
            <TR>
                <TD>Name On Card: </TD>
                <TD>
                <INPUT TYPE="text" NAME="p_cc_nameoncard" SIZE=21>
                </TD>
            </TR>
            <TR>
                <TD COLSPAN=2 ALIGN="center">
                <INPUT TYPE="submit" VALUE="Submit Order">
                </TD>
            </TR>
            </TABLE>
            </FORM>
            </CENTER>
  </FORM>
  <!--#include virtual="/pagebottom.txt"-->
  </BODY>
  </HTML>
<%  end if
 end if %>
----------------------------------------------------------------------------
------------
questo invece e baz_order_complete.asp
per la registrazione dei dati dei clienti
----------------------------------------------------------------------------
------------
<%@ LANGUAGE="VBSCRIPT" %>
<!--#include virtual="/adovbs.inc"-->
<!--#include virtual="/pagetop.txt"-->
<%
    set outpostDB = Server.CreateObject("ADODB.Connection")
    outpostDB.Open "outpost"
    p_order_id = Request.form("order_id")
    set orderSet = Server.CreateObject("ADODB.RecordSet")
    orderSet.Open "select * from baz_orders where order_id" _
        & order_id, outpostDB, adOpenStatic, adLockOptimistic, _
        adCmdText
    if orderSet.EOF then
        Response.Write "There is a problem with your order. "
        Response.Write "Please contact customer service."
    else
        orderSet("shipping") = Request.form("p_shipping")
        orderSet("first_name") = Request.form("p_first")
        orderSet("last_name") = Request.form("p_last")
        orderSet("address1") = Request.form("p_address1")
        orderSet("address2") = Request.form("p_address2")
        orderSet("city") = Request.form("p_city")
        orderSet("state") = Request.form("p_state")
        orderSet("postalcode") = Request.form("p_postal")
        orderSet("country") = Request.form("p_country")
        orderSet("phone") = Request.form("p_phone")
        orderSet("cc_type") = Request.form("p_cc_type")
        orderSet("cc_number") = Request.form("p_cc_number")
        orderSet("cc_nameoncard") = Request.form("p_cc_nameoncard")
     orderSet("total") = Request.form("p_total")
        orderSet("status") = "COMPLETE"
        orderSet.Update
        outpostDB.Execute("delete from baz_order_items where " & "order_id"
& p_order_id)
        set itemSet = Server.CreateObject("ADODB.RecordSet")
        itemSet.Open "baz_order_items", outpostDB, adOpenStatic,
adLockOptimistic, adCmdTable
        for each item in Request.form("p_orderitem")
            p_orderitem = cstr(item)
            itemInfo = split(p_orderitem, ",")
            itemSet.addNew
            itemSet("order_id") = p_order_id
            itemSet("prod_id") = itemInfo(0)
            itemSet("quantity") = itemInfo(1)
            itemSet.Update
        next
        itemSet.Close
        set itemSet = Nothing
        Session.abandon
    end if
    orderSet.Close
    set orderSet = Nothing
    outpostDB.Close
    set outpostDB = Nothing
%>
Your order has been received.  Please allow 10 business
days for receipt.
<P>
Thank you for shopping with us!
<!--#include virtual="/pagebottom.txt"-->
</BODY>
</HTML>
----------------------------------------------------------------------------
-------------------------------
questo invece e' il global.asa interessato
----------------------------------------------------------------------------
-----------------------------
<OBJECT RUNAT=Server SCOPE=Session ID=MyInfo PROGID="MSWC.MyInfo">
</OBJECT>
<OBJECT RUNAT=Server SCOPE=Application ID=Counter PROGID="MSWC.Counters">
</OBJECT>
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
    set outpostDB = Server.CreateObject("ADODB.Connection")
    outpostDB.Open "outpost"
    set maxOrderSet = outpostDB.Execute("select order_id from"_
         & " baz_orders " & "order by order_id desc")
    if maxOrderSet.EOF then
        Application("order_id") = 1
    else
        Application("order_id") = maxOrderSet("order_id") + 1
    end if
    maxOrderSet.Close
    set maxOrderSet = Nothing
    outpostDB.Close
    set outpostDB = Nothing
End Sub
Sub Session_OnStart
    Set Session("arrTo")=Server.CreateObject("Scripting.Dictionary")
    Set Session("arrCC")=Server.CreateObject("Scripting.Dictionary")
    Set Session("arrBCC")=Server.CreateObject("Scripting.Dictionary")
    Set Session("arrFiles")=Server.CreateObject("Scripting.Dictionary")
    Session("Count")=0 'to generate unique keys for the dictionaries
end sub
Sub Session_OnEnd
end sub
Sub Application_OnStart
 '==Visual InterDev Generated - startspan==
 '--Project Data Connection
  Application("Connection1_ConnectionString") =
"DSN=outpost;DBQ=E:\Inetpub\wwwroot\outpost.mdb;DriverId=25;FIL=MS
Access;MaxBufferSize=2048;PageTimeout=5;"
  Application("Connection1_ConnectionTimeout") = 15
  Application("Connection1_CommandTimeout") = 30
  Application("Connection1_CursorLocation") = 3
  Application("Connection1_RuntimeUserName") = ""
  Application("Connection1_RuntimePassword") = ""
 '-- Project Data Environment
  'Set DE = Server.CreateObject("DERuntime.DERuntime")
  'Application("DE") = DE.Load(Server.MapPath("Global.ASA"),
"_private/DataEnvironment/DataEnvironment.asa")
 '==Visual InterDev Generated - endspan==
 end sub
</SCRIPT>
Ringrazio in anticipo per la risposta
Alex

         adCmdText
Manca l'uguale nella stringa SQL,  poi il parametro č in p_order_id e poi
forse sarebbe bene convertirlo esplicitamente in numero, oppure mettere gli
apici se p_order_id č testo
la forma piů adatta dovrebbe essere "select * from baz_orders where order_id
=" & cint(p_order_id)
Paolo