出来るのだASP Q&A掲示板(過去LOG)
訪問数 52046
昨日 889
今日 776 【PR】 パソコン入門からIT専門書まで幅広く取り揃えています。セブン-イレブン受取り手数料無料のセブンアンドワイ。 |
![]() ![]() ![]() ![]() ![]() |
[4697] Re:チェックボックスのOff時の値を取得して配列に渡したい |
投稿者:はまぐりんさん 2004/10/20 6:24:43 |
おっしゃるとおりですね。 大変失礼しました。 それでは、長いですが、先頭から必要な部分まで、全部添付します。製品一覧は別ファイルになっており、カートの中身を表示する部分からこのファイルです。 問題となっているのはUpdateの部分で、チェックボックスの値を配列(s_del(i))に渡していますが、チェックされていない場合は値が渡されないため、(i)がエラーになります。 宜しくお願いします。 <% act = Request("act") prod_num = Request.Form("prod_num") prod_name = Request.Form("prod_name") mfg = Request.Form("mfg") unit_price = Request.Form("unit_price") link = Request.Form("link") qty = Request.Form("qty") special = Request.Form("special") special_price = Request.Form("special_price") call showheader() Select Case act Case "cart" Call ShoppingCart Case "update" Call Update Case "delete" Call Delete Case "kanryo" Call Kanryo Case "checkout" Call Checkout Case "grandtotal" Call grandtotal Case else Call cart end select %> <% call showFooter() '50 'カートの中身を表示(1個目) Sub cart() %> <% id = Request.QueryString("id") cus_id = session.sessionID Set ObjConn = Server.CreateObject("ADODB.Connection") ObjConn.open "driver={Microsoft Access Driver (*.mdb)}; DBQ=" & _ Server.Mappath("../Data/mail_order.mdb") Set ObjRS = Server.CreateObject("ADODB.Recordset") StrSQL = "select * from products where id = " & id ObjRS.Open StrSQL, ObjConn prod_num = ObjRS("prod_num") prod_name = ObjRS("prod_name") wei = ObjRS("wei") special = ObjRS("special") category = ObjRS("category") if special = 1 then price = ObjRS("special_price") else price = ObjRS("unit_price") end if qty = 1 total_price = FormatNumber(price * qty, 2) if ObjRS("category") = 1 or ObjRS("category") = 2 then tax = FormatNumber(total_price * 0.02) else tax = FormatNumber(total_price * 0.085) end if total_wei = FormatNumber(wei * qty) StrSQL = "insert into shopping(category, cus_id, prod_num, prod_name, qty, wei, total_wei, unit_price, total_price, special, tax)" & _ "values ('" & category & "','" & cus_id & "','" & prod_num & "','" & prod_name & "','" & qty & "','" & wei & "','" & total_wei & "','" & price & "','" & total_price & "','" & special & "','" & tax & "')" ObjConn.Execute (StrSQL) Response.Redirect "mail_order.asp?act=cart&id=" & cus_id '105 ObjRS.Close Set ObjRS = Nothing ObjConn.CLose Set ObjConn = Nothing end sub ' ショッピングカート表示 Sub shoppingcart() cus_id = Request.QueryString("id") Set ObjConn = Server.CreateObject("ADODB.Connection") ObjConn.open "driver={Microsoft Access Driver (*.mdb)}; DBQ=" & _ Server.Mappath("../Data/mail_order.mdb") Set ObjRS = Server.CreateObject("ADODB.Recordset") StrSQL = "select * from shopping where cus_id =" & cus_id ObjRS.Open StrSQL, ObjConn if ObjRS.eof and ObjRS.bof then %> <tr> <td height="5" colspan="2"> <div align="right"><font size="2" face="MS Pゴシック, Osaka"><a href="mail_order_top.asp"><br> メールオーダートップ</a> | <a href="mail_order_special.asp">特売品コーナー</a> | <a href="mail_order.asp?act=checkout&id=<%= cus_id %>">チェックアウト</a> </font></div> </td> </tr> <tr valign="top"> <td height="217" colspan="2"> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="3" height="16"><img src="Pic/MailOrder/ShoppingCart/shopping_cart_title.gif" width="762" height="67"></td> </tr> <tr valign="top"> <td height="266" colspan="3"><font size="2" face="MS Pゴシック, Osaka"><br> <br><br><br> <center>お客様のショッピングカートは空です。<br><br> <A href="JavaScript: history.back()">前のページに戻る。</a></font></center> <br> </td> </tr> <% else %> <!--// function check(){ if (document.cart.del.checked == ture) document.cart.del.value = "delete"; if (document.cart.del.checked == false) document.cart.del.value = "keep"; } --> <tr> <td height="5" colspan="2"> <div align="right"><font size="2" face="MS Pゴシック, Osaka"><a href="mail_order_top.asp"><br> メールオーダートップ</a> | <a href="mail_order_special.asp">特売品コーナー</a> | <a href="mail_order.asp?act=checkout&id=<%= cus_id %>">チェックアウト</a> </font></div> </td> </tr> <tr valign="top"> <td height="217" colspan="2"> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="3" height="16"><img src="Pic/MailOrder/ShoppingCart/shopping_cart_title.gif" width="762" height="67"></td> </tr> <tr valign="top"> <td height="266" colspan="3"><font size="2" face="MS Pゴシック, Osaka"><br> <br> お客様のショッピングカートの中身は下記の通りです。</font><br> <br> <form method="post" action="mail_order.asp?act=update&id=<%= ObjRS("cus_id") %>" name="cart"> <table width="760" bordercolor="#666666" border="1" cellspacing="0"> <tr> <td width="33" height="10" nowrap> <div align="center"><font size="2" face="MS Pゴシック, Osaka">削除</font></div> </td> <td width="58" height="10" nowrap> <div align="center"><font size="2" face="MS Pゴシック, Osaka">商品番号</font></div> </td> <td width="395" height="10" nowrap> <div align="center"><font size="2" face="MS Pゴシック, Osaka">商品名</font></div> </td> <td width="35" height="10" nowrap> <div align="center"><font size="2" face="MS Pゴシック, Osaka">個数</font></div> </td> <td width="63" height="10" nowrap> <div align="center"><font size="2" face="MS Pゴシック, Osaka">単価</font></div> </td> <td width="72" height="10" nowrap> <div align="center"><font size="2" face="MS Pゴシック, Osaka">重量</font></div> </td> <td width="74" height="10" nowrap> <div align="center"><font size="2" face="MS Pゴシック, Osaka">合計金額</font></div> </td> </tr> <% Do Until ObjRS.eof If ObjRS("special") = "1" then color = "#ff0000" else color = "#000000" end if %> <tr> <td width="33" height="18"> <div align="center"> <input type="checkbox" name="del"> </div> </td> <td width="58" height="18"><font size="2"><%= ObjRS("prod_num") %></font></td> <td width="395" height="18"><font size="2"><%= ObjRS("prod_name") %></font></td> <td width="35" height="18" align="left"> <div align="center" align="left"> <font size="2"><input type="text" name="qty" size="4" maxlength="4" value="<%= ObjRS("qty") %>"></font> </div> </td> <td width="63" height="18" align="right"><font size="2" color="<%= color %>">$<%= ObjRS("unit_price") %></font></td> <td width="72" height="18" align="center"><font size="2"><%= ObjRS("total_wei") %> Lbs</font></td> <td width="74" height="18" align="right"><font size="2" color="<%= color %>">$<%= FormatNumber(ObjRS("total_price")) %></font></td> </tr> <input type="hidden" name="prod_id" value="<%= ObjRS("id") %>"> <input type="hidden" name="prod_num" value="<%= ObjRS("prod_num") %>" > <input type="hidden" name="prod_name" value="<%= ObjRS("prod_name") %>" > <input type="hidden" name="unit_price" value="<%= ObjRS("unit_price") %>" > <input type="hidden" name="wei" value="<%= ObjRS("wei") %>" > <input type="hidden" name="total_price" value="<%= ObjRS("total_price") %>"> <input type="hidden" name="category" value="<%= ObjRS("category") %>"> <% total_price = ObjRS("total_price") t_t_price = FormatNumber(t_t_price + total_price, 2) ObjRS.MoveNext Loop %> <tr> <td colspan="6" align="right"><font size="2">小合計金額</font></td> <td align="right"><font size="2">$<%= t_t_price %></font></td> </tr> <% ObjRS.Close Set ObjRS = Nothing ObjConn.Close Set ObjConn = Nothing Set ObjConn = Server.CreateObject("ADODB.Connection") ObjConn.open "driver={Microsoft Access Driver (*.mdb)}; DBQ=" & _ Server.Mappath("../Data/mail_order.mdb") Set ObjRS = Server.CreateObject("ADODB.Recordset") StrSQL = "select * from shopping where cus_id=" & cus_id ObjRS.Open StrSQL, ObjConn %> </table> <table width="760" border="0"> <tr> <td align="right" width="530"><input type="image" src="pic/mailorder/update.jpg" name="act" onClick = "check()"></td> </form> <form method="post" action="mail_order_top.asp"> <td align="right" width="130"><input type="image" src="pic/mailorder/shopping.jpg" name="act"></td> </form> <form method="post" action="mail_order.asp?act=checkout&id=<%= ObjRS("cus_id") %>"> <td align="left" width="100"><input type="image" src="pic/mailorder/checkout.jpg" name="act"></td> </form> </tr> </table> </td> </tr> </table> <% end if %> </td> </tr> <tr> <td height="71" colspan="2"> <div align="center"><font size="2" face="MS Pゴシック, Osaka"><a href="mail_order_top.asp">メールオーダートップ</a> | <a href="mail_order_special.asp">特売品コーナー</a></font><br> </div> <hr align="center"> </td> </tr> <% ObjRS.Close Set ObjRS = Nothing ObjConn.Close Set ObjConn = Nothing End Sub ' カートの中身を更新 Sub Update Set ObjConn = Server.CreateObject("ADODB.Connection") ObjConn.open "driver={Microsoft Access Driver (*.mdb)}; DBQ=" & _ Server.Mappath("../Data/mail_order.mdb") id = Request.QueryString("id") cus_id = session.sessionID del = Request.Form("del") s_del = split(del, ",") cus_id = Request.QueryString("id") prod_id = Request.Form("prod_id") u_id = split(prod_id, ",") qty = Request.Form("qty") u_qty = split(qty, ",") wei = Request.Form("wei") u_wei = split(wei, ",") unit_price = Request.Form("unit_price") u_unit_price = split(unit_price, ",") for i = 0 to UBound(u_id) if s_del(i) = "delete" then Set ObjRS = Server.CreateObject("ADODB.Recordset") StrSQL = "delete * from shopping where id =" & u_id(i) ObjConn.Execute(StrSQL) else Set ObjRS = Server.CreateObject("ADODB.Recordset") StrSQL = "select * from shopping where cus_id =" & cus_id & " and id = " & u_id(i) ObjRS.Open StrSQL, ObjConn, 3, 3 ObjRS("qty") = u_qty(i) ObjRS("wei") = u_wei(i) ObjRS("total_wei") = FormatNumber(u_wei(i) * u_qty(i)) ObjRS("total_price") = FormatNumber(u_unit_price(i) * u_qty(i),2) ObjRS("tax") = ObjRS("total_price") * tax_rate ObjRS.Update end if Next Response.Redirect "mail_order.asp?act=cart&id=" & cus_id ObjRS.Close Set ObjRS = Nothing ObjConn.Close Set ObjConn = Nothing End Sub<!-- #include file = "includes.asp" --> <% act = Request("act") prod_num = Request.Form("prod_num") prod_name = Request.Form("prod_name") mfg = Request.Form("mfg") unit_price = Request.Form("unit_price") link = Request.Form("link") qty = Request.Form("qty") special = Request.Form("special") special_price = Request.Form("special_price") call showheader() Select Case act Case "cart" Call ShoppingCart Case "update" Call Update Case "delete" Call Delete Case "kanryo" Call Kanryo Case "checkout" Call Checkout Case "grandtotal" Call grandtotal Case else Call cart end select %> <% call showFooter() '50 'カートの中身を表示(1個目) Sub cart() %> <% id = Request.QueryString("id") cus_id = session.sessionID Set ObjConn = Server.CreateObject("ADODB.Connection") ObjConn.open "driver={Microsoft Access Driver (*.mdb)}; DBQ=" & _ Server.Mappath("../Data/mail_order.mdb") Set ObjRS = Server.CreateObject("ADODB.Recordset") StrSQL = "select * from products where id = " & id ObjRS.Open StrSQL, ObjConn prod_num = ObjRS("prod_num") prod_name = ObjRS("prod_name") wei = ObjRS("wei") special = ObjRS("special") category = ObjRS("category") if special = 1 then price = ObjRS("special_price") else price = ObjRS("unit_price") end if qty = 1 total_price = FormatNumber(price * qty, 2) if ObjRS("category") = 1 or ObjRS("category") = 2 then tax = FormatNumber(total_price * 0.02) else tax = FormatNumber(total_price * 0.085) end if total_wei = FormatNumber(wei * qty) StrSQL = "insert into shopping(category, cus_id, prod_num, prod_name, qty, wei, total_wei, unit_price, total_price, special, tax)" & _ "values ('" & category & "','" & cus_id & "','" & prod_num & "','" & prod_name & "','" & qty & "','" & wei & "','" & total_wei & "','" & price & "','" & total_price & "','" & special & "','" & tax & "')" ObjConn.Execute (StrSQL) Response.Redirect "mail_order.asp?act=cart&id=" & cus_id '105 ObjRS.Close Set ObjRS = Nothing ObjConn.CLose Set ObjConn = Nothing end sub ' ショッピングカート表示 Sub shoppingcart() cus_id = Request.QueryString("id") Set ObjConn = Server.CreateObject("ADODB.Connection") ObjConn.open "driver={Microsoft Access Driver (*.mdb)}; DBQ=" & _ Server.Mappath("../Data/mail_order.mdb") Set ObjRS = Server.CreateObject("ADODB.Recordset") StrSQL = "select * from shopping where cus_id =" & cus_id ObjRS.Open StrSQL, ObjConn if ObjRS.eof and ObjRS.bof then %> <tr> <td height="5" colspan="2"> <div align="right"><font size="2" face="MS Pゴシック, Osaka"><a href="mail_order_top.asp"><br> メールオーダートップ</a> | <a href="mail_order_special.asp">特売品コーナー</a> | <a href="mail_order.asp?act=checkout&id=<%= cus_id %>">チェックアウト</a> </font></div> </td> </tr> <tr valign="top"> <td height="217" colspan="2"> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="3" height="16"><img src="Pic/MailOrder/ShoppingCart/shopping_cart_title.gif" width="762" height="67"></td> </tr> <tr valign="top"> <td height="266" colspan="3"><font size="2" face="MS Pゴシック, Osaka"><br> <br><br><br> <center>お客様のショッピングカートは空です。<br><br> <A href="JavaScript: history.back()">前のページに戻る。</a></font></center> <br> </td> </tr> <% else %> <!--// function check(){ if (document.cart.del.checked == ture) document.cart.del.value = "delete"; if (document.cart.del.checked == false) document.cart.del.value = "keep"; } --> <tr> <td height="5" colspan="2"> <div align="right"><font size="2" face="MS Pゴシック, Osaka"><a href="mail_order_top.asp"><br> メールオーダートップ</a> | <a href="mail_order_special.asp">特売品コーナー</a> | <a href="mail_order.asp?act=checkout&id=<%= cus_id %>">チェックアウト</a> </font></div> </td> </tr> <tr valign="top"> <td height="217" colspan="2"> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="3" height="16"><img src="Pic/MailOrder/ShoppingCart/shopping_cart_title.gif" width="762" height="67"></td> </tr> <tr valign="top"> <td height="266" colspan="3"><font size="2" face="MS Pゴシック, Osaka"><br> <br> お客様のショッピングカートの中身は下記の通りです。</font><br> <br> <form method="post" action="mail_order.asp?act=update&id=<%= ObjRS("cus_id") %>" name="cart"> <table width="760" bordercolor="#666666" border="1" cellspacing="0"> <tr> <td width="33" height="10" nowrap> <div align="center"><font size="2" face="MS Pゴシック, Osaka">削除</font></div> </td> <td width="58" height="10" nowrap> <div align="center"><font size="2" face="MS Pゴシック, Osaka">商品番号</font></div> </td> <td width="395" height="10" nowrap> <div align="center"><font size="2" face="MS Pゴシック, Osaka">商品名</font></div> </td> <td width="35" height="10" nowrap> <div align="center"><font size="2" face="MS Pゴシック, Osaka">個数</font></div> </td> <td width="63" height="10" nowrap> <div align="center"><font size="2" face="MS Pゴシック, Osaka">単価</font></div> </td> <td width="72" height="10" nowrap> <div align="center"><font size="2" face="MS Pゴシック, Osaka">重量</font></div> </td> <td width="74" height="10" nowrap> <div align="center"><font size="2" face="MS Pゴシック, Osaka">合計金額</font></div> </td> </tr> <% Do Until ObjRS.eof If ObjRS("special") = "1" then color = "#ff0000" else color = "#000000" end if %> <tr> <td width="33" height="18"> <div align="center"> <input type="checkbox" name="del"> </div> </td> <td width="58" height="18"><font size="2"><%= ObjRS("prod_num") %></font></td> <td width="395" height="18"><font size="2"><%= ObjRS("prod_name") %></font></td> <td width="35" height="18" align="left"> <div align="center" align="left"> <font size="2"><input type="text" name="qty" size="4" maxlength="4" value="<%= ObjRS("qty") %>"></font> </div> </td> <td width="63" height="18" align="right"><font size="2" color="<%= color %>">$<%= ObjRS("unit_price") %></font></td> <td width="72" height="18" align="center"><font size="2"><%= ObjRS("total_wei") %> Lbs</font></td> <td width="74" height="18" align="right"><font size="2" color="<%= color %>">$<%= FormatNumber(ObjRS("total_price")) %></font></td> </tr> <input type="hidden" name="prod_id" value="<%= ObjRS("id") %>"> <input type="hidden" name="prod_num" value="<%= ObjRS("prod_num") %>" > <input type="hidden" name="prod_name" value="<%= ObjRS("prod_name") %>" > <input type="hidden" name="unit_price" value="<%= ObjRS("unit_price") %>" > <input type="hidden" name="wei" value="<%= ObjRS("wei") %>" > <input type="hidden" name="total_price" value="<%= ObjRS("total_price") %>"> <input type="hidden" name="category" value="<%= ObjRS("category") %>"> <% total_price = ObjRS("total_price") t_t_price = FormatNumber(t_t_price + total_price, 2) ObjRS.MoveNext Loop %> <tr> <td colspan="6" align="right"><font size="2">小合計金額</font></td> <td align="right"><font size="2">$<%= t_t_price %></font></td> </tr> <% ObjRS.Close Set ObjRS = Nothing ObjConn.Close Set ObjConn = Nothing Set ObjConn = Server.CreateObject("ADODB.Connection") ObjConn.open "driver={Microsoft Access Driver (*.mdb)}; DBQ=" & _ Server.Mappath("../Data/mail_order.mdb") Set ObjRS = Server.CreateObject("ADODB.Recordset") StrSQL = "select * from shopping where cus_id=" & cus_id ObjRS.Open StrSQL, ObjConn %> </table> <table width="760" border="0"> <tr> <td align="right" width="530"><input type="image" src="pic/mailorder/update.jpg" name="act" onClick = "check()"></td> </form> <form method="post" action="mail_order_top.asp"> <td align="right" width="130"><input type="image" src="pic/mailorder/shopping.jpg" name="act"></td> </form> <form method="post" action="mail_order.asp?act=checkout&id=<%= ObjRS("cus_id") %>"> <td align="left" width="100"><input type="image" src="pic/mailorder/checkout.jpg" name="act"></td> </form> </tr> </table> </td> </tr> </table> <% end if %> </td> </tr> <tr> <td height="71" colspan="2"> <div align="center"><font size="2" face="MS Pゴシック, Osaka"><a href="mail_order_top.asp">メールオーダートップ</a> | <a href="mail_order_special.asp">特売品コーナー</a></font><br> </div> <hr align="center"> </td> </tr> <% ObjRS.Close Set ObjRS = Nothing ObjConn.Close Set ObjConn = Nothing End Sub ' カートの中身を更新 Sub Update Set ObjConn = Server.CreateObject("ADODB.Connection") ObjConn.open "driver={Microsoft Access Driver (*.mdb)}; DBQ=" & _ Server.Mappath("../Data/mail_order.mdb") id = Request.QueryString("id") cus_id = session.sessionID del = Request.Form("del") s_del = split(del, ",") cus_id = Request.QueryString("id") prod_id = Request.Form("prod_id") u_id = split(prod_id, ",") qty = Request.Form("qty") u_qty = split(qty, ",") wei = Request.Form("wei") u_wei = split(wei, ",") unit_price = Request.Form("unit_price") u_unit_price = split(unit_price, ",") for i = 0 to UBound(u_id) if s_del(i) = "delete" then Set ObjRS = Server.CreateObject("ADODB.Recordset") StrSQL = "delete * from shopping where id =" & u_id(i) ObjConn.Execute(StrSQL) else Set ObjRS = Server.CreateObject("ADODB.Recordset") StrSQL = "select * from shopping where cus_id =" & cus_id & " and id = " & u_id(i) ObjRS.Open StrSQL, ObjConn, 3, 3 ObjRS("qty") = u_qty(i) ObjRS("wei") = u_wei(i) ObjRS("total_wei") = FormatNumber(u_wei(i) * u_qty(i)) ObjRS("total_price") = FormatNumber(u_unit_price(i) * u_qty(i),2) ObjRS("tax") = ObjRS("total_price") * tax_rate ObjRS.Update end if Next Response.Redirect "mail_order.asp?act=cart&id=" & cus_id ObjRS.Close Set ObjRS = Nothing ObjConn.Close Set ObjConn = Nothing End Sub |
![]() ![]() ![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
TreeBBS For ASP V.0.1.3 |