hej alle. Jeg har fundet en asp-shop på www.scannet.dk, som henter priser og produktinfo fra en accesdatabase. Se koden her:
<!--#include file="include/config.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>ASP DemoShop</title>
</head>
<body>
<h2>ASP DemoShop</h2>
[ <a href="default.asp"><b>Products</b></a> | <a href="cart.asp"><b>ShoppingCart</b></a> ]<br><br>
<h3>ShoppingCart:</h3>
<%
Cart = Session("Cart")
Items = Session("Items")
if Request.QueryString("action") = "add" then
Items = Items + 1
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open strDSN
Set RS = Conn.Execute("SELECT * FROM Products WHERE ID = "&Request.QueryString("id")&"")
if Not RS.EOF then
Cart(1,Items) = Items
Cart(2,Items) = RS("ID")
Cart(3,Items) = RS("Name")
Cart(4,Items) = RS("Price")
Cart(5,Items) = 1
end if
RS.close
Conn.Close
Set RS = nothing
Set Conn = nothing
elseif Request.QueryString("action") = "delete" then
Cart(5,Request.QueryString("id")) = 0
end if
Session("Cart") = Cart
Session("Items") = Items
%>
<table border="1" width="400">
<%
for i = from 1 to Items
if Cart(5,i) = 1 then
%>
<tr>
<td><%=Cart(3,i)%></td>
<td align="right"><%=FormatNumber(Cart(4,i))%></td>
<td> <a href="cart.asp?action=delete&id=<%=Cart(1,i)%>">Delete</a></td>
</tr>
<%
TotalPrice = TotalPrice + Cart(4,i)
end if
next
%>
</table>
<br>
<h3>Total Price: <%=FormatNumber(TotalPrice,2)%></h3>
<form action="order.asp" method="post">
<input type="Submit" value="Order Now!">
</form>
</body>
</html>
Jeg vil så bare lave den om til at hente pris, produktinfo osv fra nogle html-input felter fra en seperat side via method="post". Jeg har rettet koden lidt til så den ser således ud nu :
<html>
<body>
<head></head>
<br><br><br>
<br><br><br>
<a href="shop.asp">Shoppen</a> <a href="kurv.asp">Indkøbskurven</a>
<br><br><br>
<%
Items = Session("Items")
Cart = Session("Cart")
if Request.QueryString("action") = "add" then
Items = Items + 1
Cart(1,Items) = Items
Cart(2,Items) = request.form("antal")
Cart(3,Items) = request.form("produkt")
Cart(4,Items) = request.form("pris")
Cart(5,Items) = 1
elseif Request.QueryString("action") = "delete" then
Cart(5,Request.QueryString("id")) = 0
end if
Session("Cart") = Cart
Session("Items") = Items
%>
<table border="1" width="400">
<%
for i = 1 to Items
if Cart(5,i) = 1 then
%>
<tr>
<td><%=Cart(3,i)%></td>
<td align="right"><%=FormatNumber(Cart(4,i))%></td>
<td> <a href="cart.asp?action=delete&id=<%=Cart(1,i)%>">Delete</a></td>
</tr>
<%
TotalPrice = TotalPrice + Cart(4,i)
end if
next
%>
</table>
<br>
<h3>Total Price: <%=FormatNumber(TotalPrice,2)%></h3>
<form action="order.asp" method="post">
<input type="Submit" value="Order Now!">
</form>
</body>
</html>
Jeg får desværre en fejl. Har kørt en debug på den, og meddelelsen er følgende:
Error Code:0xB00A000D
Error Source: Cart(1,Items) = Items
Error Description : Type mismatch: Cart
File Name: c:\\inetpub\\wwwroot\\kurv.asp
Line No. : 38
Håber i kan hjælpe mig.
Mvh
christian krintel