Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 26th, 2005, 01:01 PM
Registered User
 
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to cincinnaticj7
Default 2 pages.....one problem.

I am trying to get check boxes to be slected on one page that can written to another and then sent to a access database... any ideas? Please Help.


[u]1st page. </u>




<HTML>
<HEAD>
<TITLE></TITLE>
<META name="description" content="order form">
<META name="keywords" content="product_name">
 </HEAD>


<table border=0 cellpadding=0 cellspacing=0 width=100%>
    <tr>
        <td width="130" valign=top bgcolor=#ffffff>
        </td>
        <TD valign=top height="100%" width="1" bgcolor="#000000"><img src="/images/sp.gif" width="1" height="1"></td>

        <TD valign=top width="100%">
            <input type=button value="Home Page" onclick="window.open('default2.asp','_self')" style="font-weight:bold;color=black;background-color:F0F1F7" id=button1 name=button1>
            <input type=button value="View Basket" onclick="window.open('cart.asp','_self')" style="font-weight:bold;color=black;background-color:F0F1F7" id=button1 name=button1>
            <input type=button value="Checkout" onclick="window.open('checkout.asp','_self')" style="font-weight:bold;color=black;background-color:F0F1F7" id=button1 name=button1>

<%
'display all products in the database

sql="select * from products "
' product_name
' Response.write sql
set objrs=objconn.execute(sql)
if not objrs.eof then
while not objrs.eof
%>


<%
dim iNum 'the number of checkboxes to generate
dim strAll 'a comma delinated list of all the values
dim i 'a loop counter
dim arrAll 'an array which will hold all of the values
dim arrVals 'an array to hold all checked values
'dim arrInactive() 'an array to hold all unchecked values
dim bThere 'a boolean match variable
dim IDX 'an index variable
dim strSql 'the resulting SQL string
dim z 'a loop counter

iNum = Request.QueryString ("numBoxes")

if iNum = "" then
    iNum = 1
end if

if Request.Form = "" then

    strAll = ""
    %>

    <form name="form1" action="chkBoxes.asp" method="post">
        <table>
        <%
        '**********************
        'this would be your recordset loop
        'basically replace i with the ID of the record.
        for i = 1 to iNum
        %>
            <tr>
                <td>Checkbox<%=i%>:</td>
                <td><input type="checkbox" name="chkBox" value="<%=i%>"></td>
            </tr>
        <%
            'append the id to strAll
            strAll = strAll & i & ","
        next
        %>

        </table>
        <%
        'trim off the trailing ","
        strAll = left(strAll, (len(strAll) -1))
        %>
        <input type="hidden" name="allBoxes" value="<%=strAll%>">
    </form>
<%
else
    'get the array with all of the checkbox id's
    arrAll = split(Request.Form ("allBoxes"), ",")

    'get the array with the id's that were ticked
    arrVals = split(Request.Form ("chkBox"), ",")

    strSql = ""
    strSql = strSql & "UPDATE aTable SET active = 1 WHERE "

    'loop through the checkboxes which were ticked
    for i = 0 to ubound(arrVals)
        if i = 0 then
            strSql = strSql & "id = "& arrVals(i)
        else
            'only add the " AND " if this is not the first value
            strSql = strSql & " AND id = "& arrVals(i)
        end if
    next

    Response.Write strSql & ""

    'dimension the array to the size we need
    redim arrInActive(ubound(arrAll) - ubound(arrVals))

    'set our indexer variable
    IDX = 0

    'loop through all the checkbox values
    for i = 0 to ubound(arrAll)
        'a boolean value to check if we match or not
        bThere = false
        'loop through the values which were submitted
        for z = 0 to ubound(arrVals)
            'if it is found then set the boolean to true
            'this is so we don't add it to the new array
            if trim(arrVals(z)) = trim(arrAll(i)) then
                bThere = true
            end if
        next
        'if it wasn't in the submitted array (i.e. it wasn't checked)
        if bThere = false then
            'add the value to the new array
            arrInactive(IDX) = arrAll(i)
            'increment our indexer
            IDX = IDX + 1
        end if
    next

    strSql = ""
    strSql = strSql & "UPDATE aTable SET active = 0 WHERE "
    'loop through the array which holds the values that were NOT ticked
    for i = 0 to ubound(arrInactive)
        if arrInactive(i) <> "" then
            if i = 0 then
                strSql = strSql & "id = "& arrInactive(i)
            else
                'only add the " ADD " if this is not the first variable
                strSql = strSql & " AND id = "& arrInactive(i)
            end if
        end if
    next

    Response.Write strSql
end if
%>





<table border=0 cellpadding=5 cellspacing=5 width=100%>
<TR>

        <form method="insert" name="product_name" action="cart.asp">


        <td align="left" valign="top">
        <input type="hidden" name="product_name" id="product_name"><b><%=objrs("product_name")%></b>
        <input type="checkbox" name="product_id" value="1" >
        <td height="100%" bgcolor="ffffff">
        <input type="hidden" name="allBoxes" value="1">

    <tr>
        <td align="left" valign="top">
            <table border="0" cellspacing="0" cellpadding="0">
                <tr>
                        </td>
                        <td valign="top">


    <p>


    <table border="0" cellspacing="0" cellpadding="3">
    <tr>

        </td>
    </tr>
    </table>








    <p>

     </td>
</tr>
</table>
</td>
</tr>
</table>
<table border=0 cellpadding=5 cellspacing=5 width=100%>
<TR>

<p>
</b>

  <%
  objrs.movenext
  wend

end if
%>
&nbsp;<br>
</td>
</tr>
</table></td>
</tr>
</table>
<p>
</td>
<input type="hidden" name="allBoxes" value="1">
<p align="center"><input onclick="window.open('<%=home_dir%>cart.asp','_sel f')" input type=submit value="Submit Your Order" style="width:150;color=black;background-color:F0F1F7" id=button2 name=button2></p>
<p style="text-align:right; margin:6px 0px 2px 0px; padding:0px;"><p align="center"><a href="#top"></p>


</tr>


</table>
</td>


</form>
</BODY>
</HTML>


[u]2nd Page </u>

<%'prevent cacheing
Response.CacheControl = "no-store"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
%>

<%
quantity=0
saved_quantity=0
Subtotal=0


'establish the basket id in a session and a cookie.
'if it doesn't exist then enter a new basket into the database.
if session("basket_id")="" then
    if request.cookies("basket_id")="" then
        sql="select max(basket_id) from basket"
        set objrs=objconn.execute(sql)
        if not objrs.eof then
            max_basket_id=cint(objrs(0))+1
            basket_id=max_basket_id
            sql="insert into basket (user_id) values ("&basket_id&")"
            objconn.execute(sql)
            response.Cookies("basket_id")=max_basket_id
            response.Cookies("user_id").expires=#1/1/2010 00:00:00#
            session("basket_id")=max_basket_id
        else
            Response.write "error"
            Response.end
        end if
    else
        session("basket_id")=request.cookies("basket_id")
        basket_id=request.cookies("basket_id")
    end if
else
basket_id=session("basket_id")
end if

catid=request.querystring("catid")
if catid<>"" then
' it's an action from this page.

    if request.querystring("act")="add" then
        call add(catid, basket_id)
    end if

    if request.querystring("act")="addtocart" then
        call addtocart(catid, basket_id)
    end if


    if request.querystring("act")="save" then
        call addtosave(catid, basket_id)
    end if


    if request.querystring("act")="delete" then
        call delete_product(catid, basket_id)
    end if
end if
%>
<HTML>
<HEAD>
<TITLE></TITLE>
<META name="description" content="">
<META name="keywords" content="">
</HEAD>


<table border=0 width=100% cellspacing=0 cellpadding=0 valign=top>
    <tr>
        <td valign=top>
            <table width=100% border=0 cellpadding=0 cellspacing=0 align=center>
                <tr valign=top>
                    <td bgcolor=#000000><img src="<%=home_dir%>images/sp.gif" width=1 height=1></td>
                    <td bgcolor=#000000><img src="<%=home_dir%>images/sp.gif" width=1 height=1></td>
                    <td><img src="<%=home_dir%>images/sp.gif" width=10 height=1></td>
                    <td align=left>
                        <table width=100% cellspacing=5 cellpadding=5 border=0>
                            <tr>
                                <td>
                                <p>
                                <input type=button value="Home Page" onclick="window.open('default2.asp','_self')" style="font-weight:bold;color=white;background-color:#FFCC00" id=button1 name=button1>
                                <TABLE cellpadding=0 cellspacing= border=0 width=100% >
                                    <tr>
                                        <td height=1 width=100% class=box_head>&nbsp;&nbsp;<h3>Your shopping cart items.</h3></td>
                                    </tr>
                                </table>
                                <table border=0 cellpadding=5 cellspacing=5 width=95%>
                                <form name=form1 action="cart.asp" method="POST" enctype="application/x-www-form-urlencoded"><p align="center"><img border="0" src="images/sp.gif"></p>





                                <%
                                'display the main shopping cart
                                call show_basket(basket_id,0)
                                'display any saved items.
                                call show_basket(basket_id,1)%>
                                </form>
                                </table>
<%if (quantity=0 and saved_quantity=0) then
    'the shopping cart is empty
    %>
    <table border=0 cellpadding=5 cellspacing=5 width=95%>
        <TR>
            <td align="left" valign="top">


            <p>
            <b>You currently have no items in your shopping basket.
            <p>To Continue Shopping: Simply browse or search the site using the links to the left or at the top.
            </b>
            </td>
        </tr>
    </table>
<%else%>
<table border=0 cellpadding=5 cellspacing=5 width=95%>
    <form action="checkout.asp?act=start" method="POST" enctype="application/x-www-form-urlencoded">
    <TR>
        <td align="left" valign="top">


        <%if quantity>0 then%>
            <table align=center border=0 cellpadding=0 cellspacing=0 width="100%">
                <tr bgcolor="#FFCC00">
                    <td align=left valign=top><input type=button value="Continue Shopping" onclick="window.open('default2.asp','_self')" style="width:150;color=white;background-color:#0000FF"></td>
                    <td valign=top height="35" align="right">
                    <input type=button value="Proceed to Checkout" onclick="window.open('checkout.asp','_self')" style="font-weight:bold;color=white;background-color:#0000FF" ></a>
                    </td>
                </tr>
            </table>
        <%end if%>
        <br><br><b>You may continue shopping
        <%if saved_quantity>0 then Response.write ", or you may move saved items to your cart"%>
        <%if quantity>0 then Response.write ", or you may checkout."%>
        </b>
        <p><b>To Continue Shopping:</b> Simply browse or search the site using the links to the left or at the top. You can easily return to this page by clicking "View Basket" at the top of any page to complete your purchase.
        <%if saved_quantity>0 then%>
            <p><b>To Move items into the cart:</b> Simply click the 'Move To Cart' button on any items you'd like to purchase. You will then have the option to checkout.
        <%end if%>
        <%if quantity>0 then%>
            <p><b>To Checkout:</b> Click the 'Proceed to Checkout' button.
            <p><p>
            </td>
            </tr>
            </table>
            </form>
        <%end if%>
<%end if%>
    </td>
</tr>
</table>


    </td>
</tr>
</table>
    </td>
</tr>
</table> </td>
</tr>
</table>


</BODY>
</HTML>




<%



'
'
'the various action functions
'_________________________________________

function add(catid,basket_id)
    sql="select product_id from basket_products where basket_id=" & basket_id &_
        " and saved=0 and product_id="&catid
    set objrs=objconn.execute(sql)
    if objrs.eof then

    sql="insert into basket_products(product_id,basket_id,saved,quantit y)" & _
            " values ("&catid&","&basket_id&","&"0,1)"


        objconn.execute(sql)
    end if
end function


function addtocart(catid,basket_id)
    sql="update basket_products set saved=0 where basket_id=" & basket_id &" and product_id=" & catid
    objconn.execute(sql)
end function



'_________________________________________

function addtosave(catid,basket_id)
    sql="update basket_products set saved=1 where basket_id=" &basket_id&" and product_id=" & catid
    objconn.execute(sql)
end function

'_________________________________________

function delete_product(catid,basket_id)
    sql="delete from basket_products where basket_id=" &basket_id&" and product_id=" & catid
    objconn.execute(sql)
end function

'_________________________________________

function show_basket(basket_id,saved_value)

    sql="select b.product_name,b.product_price,b.product_id,a.quan tity,b.product_short_description " & _
        " from basket_products a , products b where a.basket_id=" & basket_id & _
        " and a.saved=" &saved_value&" and a.product_id=b.product_id"


        set objrs=objconn.execute(sql)
        if not objrs.eof then

        if saved_value=0 then
        quantity=1
        %>
        <TR bgcolor="#FFCC00">
            <td align="left" valign="top">

            <b>Shopping Cart Items -> To Buy Now</b>
            </td>
            <td align="center" valign="top">
            Qty
            </td>
            <td align="left" valign="top">

            </td>
            <td align="left" valign="top">&nbsp;
            </td>
        </tr>
        <%else
            saved_quantity=1%>
            <TR bgcolor="#FFCC00">
                <td align="left" valign="top">

                <b>Saved Items -> To Buy Later</b>
                </td>
                <td align="center" valign="top">
                &nbsp;&nbsp;&nbsp;
                </td>
                <td align="left" valign="top">
                Price
                </td>
                <td align="left" valign="top">&nbsp;
                </td>
            </tr>

        <%end if
        while not objrs.eof%>
            <TR>
                <td align="left" valign="top" width="51%">

                <b><a href="item_detail.asp?product_id=<%=objrs("product _id")%>"><%=objrs("product_name")%></a></b><br>
                <%=objrs("product_short_description")%>
                </td>
                <td align="center" valign="top" width="7%">
                <%if saved_value=0 then
                    basket_quantity=objrs("quantity")
                    if isnull(basket_quantity) then basket_quantity=1
                    basket_quantity=cint(basket_quantity)
                    prod_quant=request.form("quantity"&objrs("product_ id"))
                        if prod_quant<>"" then
                            if isnumeric(prod_quant) then
                                sql="update basket_products set quantity="&prod_quant&" where basket_id=" &basket_id&" and product_id=" & objrs("product_id")
                                objconn.execute(sql)
                                basket_quantity=prod_quant
                            end if
                        end if
                        Subtotal=Subtotal+(formatnumber(objrs("product_pri ce"),2)*cint(basket_quantity))%>

                <%end if%>
                </td>
                <td align="left" valign="top" width="25%">




                </td>
                <td align=right width="13%">
                <%if saved_value=0 then%>
                <input type=button value="Save For Later" onclick="window.open('cart.asp?temp=<%=temp%>&act= save&catid=<%=objrs("product_id")%>','_self')" style="width:120;color=black;background-color:#FFCC00" >
            <%else%>
                <input type=button value="Move To Cart" onclick="window.open('cart.asp?temp=<%=temp%>&act= addtocart&catid=<%=objrs("product_id")%>','_self') " style="width:120;color=black;background-color:#FFCC00" >
            <%end if%>

                <p>
                <input type=button value="Delete" onclick="window.open('cart.asp?temp=<%=temp%>&act= delete&save_val=<%=saved_value%>&catid=<%=objrs("p roduct_id")%>','_self')" style="width:120;color=black;background-color:#FFCC00" >

                </td>
            </tr>
            <%
        objrs.movenext
    wend
    if saved_value=0 then
        %>
        <tr>
            <td align=right valign=middle>

            <nobr>All items are limited to a quantity of one......</nobr>
            </td>
            <td valign=middle>
            <input type=submit value="Update item" border="0" style="width:120;color=black;background-color:#FFCC00" >
            </td>
            <td align="left" valign="top" width="25%">


            </td>
            <td align=right width="13%"></td>
        </tr>

<% end if
show_basket="true"
end if

end function
'_________________________________________
%>




 
Old January 26th, 2005, 02:07 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Can you describe the problem in more detail? It's bit too much code to a) find out how it's supposed to work, b) what the problem might be and c) provide a fix for it....

Cheers

Imar





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in getting more then 10000 pages report meetkotresh J2EE 1 February 2nd, 2008 02:22 AM
problem with two pages launching Diggers33 Flash (all versions) 2 January 25th, 2007 07:39 AM
Tap Pages Problem kfls_83 ADO.NET 0 November 21st, 2004 07:54 AM
IIS Problem with ASP Pages rodmcleay Classic ASP Basics 2 April 18th, 2004 08:47 PM
Problem with ASP pages hanging tservo BOOK: Beginning ASP 3.0 1 September 19th, 2003 11:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.