2017-08-03 73 views
0

目前我正在尝试开发在线购物网站。当我点击添加到购物车按钮数据没有插入时,我很难将数据插入到数据库表中。任何有专业知识的人都可以告诉我问题在哪里?以下是我的代码。当点击结帐按钮时将数据插入数据库

$sqlSelectProdCat1 = mysql_query("select * from tblproduct where prod_cat = 'Hall Package'") or die(mysql_error()); 
if(mysql_num_rows($sqlSelectProdCat1) >= 1){ 
    $displayProdCat .= '<h2></h2>'; 
    while($getProdInfo1 = mysql_fetch_array($sqlSelectProdCat1)){ 
     $prodNo = $getProdInfo1["prod_no"]; 
     $prodId = $getProdInfo1["pro_id"]; 
     $prodName = $getProdInfo1["prod_name"]; 
     $prodDescri = $getProdInfo1["prod_descri"]; 
     $hallservice= $getProdInfo1["hall_service"]; 
     $prodPrice = $getProdInfo1["prod_price"]; 
     $displayProdCat .= '<form method="post" action="choosepackage.php" /><div class="team-row"><div class="col-md-9 w3ls-team-grids" > 
         <div class="grid_3 grid_5 wow fadeInUp animated" data-wow-delay=".5s"> 
         <h5>'.$prodName.'</h5> 
         <h4>RM'.$prodPrice.'</h4> 
         <h4>(Minimum pax:1000)</h4> 
         <p>'.$prodDescri.'</p> 

        </br> 
        <h6>Service include:</h6> 
        <p><strong>'.$hallservice.'</strong></p> 

        <h1> 
         <a href="cart.php?prodid='.$prodId.'" ><span class="label label-danger">Add to Cart</span></a> 
        </h1> 
         <button type="submit" name="order" class="btn btn-success"><i class="icon-plus-sign"></i>&nbsp;Add</button> 
         <input type="hidden" name="quantity" value="1"> 
         <input type="submit" name="continue" class="button-w3layouts hvr-rectangle-out"> 
        </div> 
        </div></form>'; 



     if(++$prodCatCtr == 4) 
      break; 

    } 

    <?php 

        if (isset($_POST['continue'])) { 
        $quantity = $_POST['quantity']; 

        $con = mysqli_connect("localhost","root",""); 
        if (!$con){ 
         die("Can not connect:" . mysql_error()); 
        } 

        mysqli_select_db($con,"mywedding"); 

        mysqli_query($con,"insert into tblorderitem (customerid,productid,productname,productimage,productprice,productquantity,orderstatus) values('$session1','$prodId','$prodName','$prodNo','$prodPrice','$quantity',Pending')"); 

        echo "done"; 
        } 
        ?> 

} 
+0

它重定向到** cart.php **。在哪个页面中插入? –

+0

您也没有在该插入语句上检查错误(它也似乎缺少一个''') –

+1

**请勿**使用**弃用和不安全** _mysql _ * - 函数。从PHP 5.5(2013年)开始,它们已被弃用,并且在PHP 7中(2015年)完全删除。改用MySQLi或PDO。 2.您对** [SQL Injections](http://php.net/manual/en/security.database.sql-injection.php)广泛开放,并且确实应该使用[Prepared Statements](http:/ /php.net/manual/en/mysqli.quickstart.prepared-statements.php)而不是连接你的查询,如果你使用上面提到的MySQLi或PDO,可以使用它们。 –

回答

0

我建议你先把它分成多个文件。然后仔细看看你的表单,因为它没有传递你想要添加到购物车的产品的任何信息。

此外,将productId插入tblorderitem而不是整个产品及其所有数据会更明智。

相关问题