Dynamic check boxes writing to database..help!!
I am trying to be able to to make a an ASP page that takes the database information writes it next a checkbox and when the checkbox is..checked. Then it can send into a 'shopping cart' database. I believe I have some of it correct in the coding listed below but I really do need some help I am still new to ASP.
<HTML>
<HEAD>
<TITLE></TITLE>
<META name="description" content="">
<META name="keywords" content="">
</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%>
<table border=0 cellpadding=5 cellspacing=5 width=100%>
<TR>
<form name="input" action="http://siteprotect/inc2/cart.asp" method="get">
<td align="left" valign="top">
<input type="hidden" name="product_name" id="product_name"><b><%=objrs("product_name")%></b>
<input type="checkbox" value="yes" name="yes">
<td height="100%" bgcolor="ffffff">
<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
%>
<br>
</td>
</tr>
</table></td>
</tr>
</table>
<p>
</td>
<p align="center"><input onclick="window.open('<%=home_dir%>cart.asp?act=ad d&catid=<%=objrs("product_name")%>','_self')" input type=submit value="Submit" style="width:150;color=black;background-color:F0F1F7" id=button2 name=button2></p>
</tr>
</table>
</td>
!!!That was the check box for above...below is what I am trying to write to.!!!!
<%'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> <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">
</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">
</td>
<td align="left" valign="top">
Price
</td>
<td align="left" valign="top">
</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
'_________________________________________
%>
|