ColdFusion购物车

ColdFusion购物车,coldfusion,shopping-cart,Coldfusion,Shopping Cart,更新:我正在重写每个页面的所有代码以及错误消息。。。请记住,我是一个非常新的,老实说,不知道这个代码的一些 productlist.cfm第1页:根据select语句生成的硬编码产品列表代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en"> <

更新:我正在重写每个页面的所有代码以及错误消息。。。请记住,我是一个非常新的,老实说,不知道这个代码的一些

productlist.cfm第1页:根据select语句生成的硬编码产品列表代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <link rel="stylesheet" href="http://students.uwf.edu/jeb48/css/style.css" type="text/css" />
 <link rel="stylesheet" href="http://students.uwf.edu/jeb48/css/style.css" type="text/css" />
 <link rel="stylesheet" href="http://students.uwf.edu/jeb48/css/bootstrap.css" type="text/css" />
 <link rel="stylesheet" href="http://students.uwf.edu/jeb48/css/bootstrap-theme.min.css" type="text/css" />
 <link rel="stylesheet" href="http://students.uwf.edu/jeb48/css/bootstrap.min.css" type="text/css" />
 <script type = "text/javascript" src="http://students.uwf.edu/jeb48/week8/assignments/scripts/jbrown.js"></script>
 <script type = "text/javascript" src="http://students.uwf.edu/jeb48/week8/assignments/scripts/jbrown2.js"></script>
 <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
 <script type = "text/javascript" src = "http://code.jquery.com/jquery-latest.js" ></script>
 <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
 <title>Scuba Diving is Fun!</title>
</head>
<body>
 <div class="container">
<cfquery name = "getlist" datasource="jeb48_shoppingcart">
 SELECT ProductID, ProductName, ProductQty, ProductPrice, ProductDescription, ProductPhoto
 FROM Products;
</cfquery>
          <div class="row">
            <div class="col-md-2"><b>Product Photo</b></div>
            <div class="col-md-2"><b>Product ID</b></div>
            <div class="col-md-2"><b>Product Name</b></div>
            <div class="col-md-2"><b>Quantity in Inventory</b></div>
            <div class="col-md-2"><b>Product Description</b></div>
            <div class="col-md-2"><b>Unit Price</b></div>
          </div !--row> 
          <cfoutput query ="getlist"> 
          <div class="row  equallist">
            <div class="col-md-2">#getlist.ProductPhoto#</div>
            <div class="col-md-2">#getlist.ProductID#</div>
            <div class="col-md-2">#getlist.ProductName#</div>
            <div class="col-md-2"><div style="text-align:center">#getlist.ProductQty#</div></div>
            <div class="col-md-2"><div style="text-align:left">#getlist.ProductDescription#</div></div>
            <div class="col-md-2"><div style="text-align:left">#DollarFormat(getlist.ProductPrice)#
            <cfif #getlist.ProductQty# gt 0>
            <br><a href = "scart.cfm?productid=#getlist.productid#&qty=1&action=add">Add to Cart</a>
            <cfelse>
            <br>Out of Stock!
            </cfif>
</div></div>
          </div !--row>
          </cfoutput>
        </div !--container>
   </body>
</html>
scart.cfm第2页:这是我遇到麻烦的页面。。。我知道我的代码是一团糟,但我不知道如何修复它。。。我得到的错误在这页上。。。该错误是ARRAYAPPEND函数的参数验证错误。我正在尝试基于上一页中的链接构建购物车

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
  <head>
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <link rel="stylesheet" href="http://students.uwf.edu/jeb48/css/style.css" type="text/css" />
 <link rel="stylesheet" href="http://students.uwf.edu/jeb48/css/bootstrap.css" type="text/css" />
 <link rel="stylesheet" href="http://students.uwf.edu/jeb48/css/bootstrap-theme.min.css" type="text/css" />
 <link rel="stylesheet" href="http://students.uwf.edu/jeb48/css/bootstrap.min.css" type="text/css" />
 <link rel="stylesheet" href="http://students.uwf.edu/jeb48/css/style.css" type="text/css" />
 <script type = "text/javascript" src="http://students.uwf.edu/jeb48/week8/assignments/scripts/jbrown.js"></script>
 <script type = "text/javascript" src="http://students.uwf.edu/jeb48/week8/assignments/scripts/jbrown2.js"></script>
 <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
 <script type = "text/javascript" src = "http://code.jquery.com/jquery-latest.js" ></script>
 <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
 <title>Scuba Diving is Fun!</title>
</head>
<body>


        <div class="container">
        <h3><center>Your Shopping Cart</center></h3>            
        <cfparam name="url.productid" default="">
        <cfparam name="url.qty" default="">
        <cfquery name = "getCartItem" datasource="jeb48_shoppingcart">
           SELECT ProductID, ProductName, ProductQty, ProductPrice, ProductDescription, ProductPhoto
           FROM Products
           WHERE ProductID = #url.productid#;
        </cfquery>

        <cfset arrShoppingCart = arrayNew(1) />
        <cfparam name="session.cart" default="arrayNew()">
        <cfset arrayAppend( "session.cart", structNew() )>
        < cfset session.cart = arrayNew(1) >
        < cfset thisCartItem = arraylen( session.cart )>
        <cfset arrayAppend( session.cart, structNew() )>
        < cfset thisCartItem = arraylen( session.cart )>
        < cfset session.cart[thisCartItem].itemID = url.productid>
        < cfset session.cart[thisCartItem].quantity = url.qty>
</body>
</html>
application.cfc

<cfcomponent> 
<cfset this.name = "jeb48SC"> 
<cfset this.datasource = "jeb48_shoppingcart"> 
<cfset this.loginstorage="Session"> 
<cfset this.sessionmanagement="Yes"> 
<cfset this.sessiontimeout="#createtimespan(0,0,45,0)#"> 
</cfcomponent>

一旦我得到这个工作,我可以开始工作,让输出建立。。。感谢您的关注。

问题的细节已发生重大变化,请编辑我的答案

哦,因为您正在application.cfc中使用this.datasource,所以不需要在此处提供数据源。因此,您的查询看起来就像,这使得您的应用程序更具移动性

<cfquery name="..."> or <cfquery> for queries where name isn't useful.
致:


其工作方式是,如果未定义变量,检查将停止。如果定义了变量,则检查将继续验证它是否为数组。

由于您是CF新手,您可能希望将此发布到以获取一些反馈-我认为大多数有经验的ColdFusion开发人员至少会做3件不同的事情谢谢大家的帮助。我会检查这一点,并标记邓肯建议的答案+1。例如,当前查询使数据库容易受到sql注入的攻击。在所有变量查询参数上使用cfqueryparam非常重要。它的许多好处之一是防止标准sql注入。@JasonBrown我更新了我的答案。我仍然收到相同的错误消息。如果有帮助,我可以发布所有页面的代码。我只是不想发布太多不必要的文本。@JasonBrown是的,请通过编辑将错误附加到原始问题中。哇,这太棒了。谢谢你这么好的解释。今天我将对此进行研究。在将会话名称更改为consistant session.scart并进行更改后,我得到了函数ARRAYNEW的错误参数验证错误。该函数采用1个参数。查找错误后,我不得不将所有ArrayNew更改为Array1,其中一些不匹配。代码没有错误。现在我必须深入研究如何从productlist页面接受输入,并实际构建购物车列表并在会话中显示信息
   <cfquery name = "getCartItem" datasource="jeb48_shoppingcart">
       SELECT ProductID, ProductName, ProductQty, ProductPrice, ProductDescription, ProductPhoto
       FROM Products
       WHERE ProductID = <cfqueryparam cfsqltype="cf_sql_integer" value="#url.productID#">
    </cfquery>
<cfquery name="..."> or <cfquery> for queries where name isn't useful.
<cfif not isDefined("session.scartItems")>
<cfif not isDefined("session.scartItems") or not isArray(session.sCartItems)>