|
|
|
ตะกร้าสินค้า ไม่เพิ่มรายการสั่งซื้อ พอเลือกรายการซื้อที่2 รายการแรกในตะกร้าก็หาย แก้ตรงไหนค่ะ |
|
|
|
|
|
|
|
Code (PHP)
<? error_reporting(0);
session_start();
include ('admin/module/connect.php');
include ('admin/module/function.php');?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>-: E-Commerce :-</title>
<link href="admin/css/style.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="admin/module/function.js"></script>
</head>
<body>
<?
$Act=$_GET['Act'];
switch($Act){
case 'Add' : $ProductId=$_GET['ProductId'];
if($ProductId != ""){
for($Check=0;$Check<=count($_SESSION['ProductId']);$Check++){
$SelectProduct=Select("ecom_product","WHERE ProductId='".$_SESSION['ProductId'][$Check]."'");
$Product=mysql_fetch_array($SelectProduct);
if($Product){
$Count=$Count+1;
}
}
if($Count<8){
for($CAdd=0;$CAdd<=count($_SESSION['ProductId']);$CAdd++){
if($_SESSION['ProductId'][$CAdd]==$ProductId){
$Same=$Same+1;
}
}
if($Same == 0){
$_SESSION['Str']=$_SESSION['Str']+1;
$_SESSION['ProductId'][$_SESSION['Str']]=$ProductId;
$_SESSION['Quanlity'][$_SESSION['Str']]=1;
}
}else{
echo "<script language=\"javascript\">";
echo "alert('ตระกร้าเต็ม');";
echo "window.location='cart.php';";
echo "</script>";
}
}
break;
case 'Del' : $Str=$_GET['Str'];
$_SESSION['ProductId'][$Str]="";
$_SESSION['Quanlity'][$Str]="";
echo "<script language=\"javascript\">";
echo "window.location='cart.php';";
echo "</script>";
break;
case 'Update' : $Str=$_POST['Str'];
$Quanlity=$_POST['Quanlity'];
for($NoUp=0;$NoUp<=count($Str);$NoUp++){
$_SESSION['Quanlity'][$Str[$NoUp]]=$Quanlity[$NoUp];
}
echo "<script language=\"javascript\">";
echo "alert('ระบบคำนวนเรียบร้อยแล้ว');";
echo "window.location='cart.php';";
echo "</script>";
}
?>
<div id="divSwap">
<div id="divLogo"></div>
<div id="divMenu"><? include ('menu.php');?></div>
<div id="divStyle">
<div id="divLoginOutLine">
<div id="divLoginInLine">
<? include('login.php');?>
</div>
</div>
<div id="divMenuCatOutLine">
<div id="divMenuCatInLine">
<? include('menu_category.php'); ?>
</div>
</div>
<div id="divNewOutLine">
<div id="divNewInLine">
</div>
</div>
<div id="divPromotionOutLine">
<div id="divPromotionInLine"></div>
</div>
<div id="divFullTitle">
<table width="100%" border="0">
<tr>
<td><div class="F-BL-Title">SHOPPING CART </div></td>
</tr>
<tr>
<td><img src="admin/image/line/line-full.png" width="670" height="5" /></td>
</tr>
</table>
</div>
<div id="divFullOutLine">
<div id="divFullInLine">
<form action="?Act=Update" method="post">
<table width="682" border="0" cellpadding="2">
<tr>
<td> </td>
<td colspan="6"> </td>
<td> </td>
</tr>
<tr>
<td width="4"> </td>
<td width="44"><div class="F-Object-Thai"><div class="F-Center">ลำดับ</div></div></td>
<td width="345"><div class="F-Object-Thai"><div class="F-Center">รายการสินค้า</div></div></td>
<td width="58"><div class="F-Object-Thai">
<div class="F-Center">ราคา</div></div></td>
<td width="69"><div class="F-Object-Thai">
<div class="F-Center">จำนวน</div></div></td>
<td width="66"><div class="F-Object-Thai"><div class="F-Center">ราคารวม</div></div></td>
<td width="41"><div class="F-Object-Thai"><div class="F-Center">ลบ</div></div></td>
<td width="5"> </td>
</tr>
<tr>
<td colspan="8"><img src="admin/image/line/line-full.png" width="670" height="5" /></td>
</tr>
<? $No=0;
for($i=0;$i<=count($_SESSION['ProductId']);$i++){
$Select=Select("ecom_product","WHERE ProductId='".$_SESSION['ProductId'][$i]."'");
$Product=mysql_fetch_array($Select);
if($Product){
$No++;
?>
<tr id="Cart<?=$i;?>" onmouseover="MouseOverMenu('Cart<?=$i;?>');" onmouseout="MouseOutMenu('Cart<?=$i;?>');"<? if($ProductId==$_SESSION['ProductId'][$i]){ echo "class=\"MouseOverMenu\""; }?> >
<td width="4"> </td>
<td><div class="F-Object-Eng"><div class="F-Center"><?=$No;?></div></div></td>
<td><div class="F-Object-Eng"><? echo iconv_substr($Product['ProductName'],0,50,"UTF-8"); ?></div></td>
<td><div class="F-Object-Eng"><div class="F-Center"><? echo number_format($Product['Price'],2,'.',','); ?></div></div></td>
<td><div class="F-Center">
<input type="hidden" name="Str[]" value="<?=$i;?>" />
<input type="number" class="InputNum" name="Quanlity[]" id="Quanlity<?=$i;?>" value="<? echo $_SESSION['Quanlity'][$i];?>" onblur="CheckNum('Quanlity<?=$i;?>');" />
</div></td>
<td><div class="F-Object-Eng"><div class="F-Center">
<? echo number_format($Price=($Product['Price']*$_SESSION['Quanlity'][$i]),2,'.',','); $Total=$Total+$Price;?>
</div></div></td>
<td><div class="F-Center"><a href="?Act=Del&Str=<?=$i;?>"><img src="admin/image/icon/ed_delete.gif" border="0"/></a></div></td>
<td> </td>
</tr>
<tr>
<td colspan="8"><img src="admin/image/line/line-full.png" width="670" height="5" /></td>
</tr>
<?
}
}
?>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td colspan="2"><div class="F-Object-Thai">ค่าจัดส่ง</div></td>
<td><div class="F-Object-Thai"><div class="F-Center">ฟรี</div></div></td>
<td><div class="F-Object-Thai"><div class="F-Center">บาท</div></div></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td colspan="2"><div class="F-Object-Thai">ราคารวมทั้งสิ้น</div></td>
<td><div class="F-Object-Eng"><div class="F-Center"><font size="4" color="#990000"><? echo number_format($Total,2,'.',','); ?></font></div></div></td>
<td><div class="F-Object-Thai"><div class="F-Center">บาท</div></div></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td colspan="6"><div class="F-Center">
<input type="button" class="Btn" value="ซื้อต่อ" onclick="window.location='index.php';" />
<input type="submit" class="Btn" value="คำนวนเงิน" />
<input type="button" class="Btn" value="ชำระเงิน" onclick="window.location='confirm.php';" />
</div></td>
<td> </td>
</tr>
</table>
</form>
</div>
</div>
</div>
<div id="divFooter"><? include('footer.php');?></div>
</div>
</body>
</html>
Tag : PHP
|
|
|
|
|
|
Date :
2015-11-09 13:31:17 |
By :
snikker |
View :
756 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมว่ามันน่าจะไป write ตัว session ทับครับ ลองดูตัวนี้ครับ Code ง่ายมาก
Code (PHP)
<?
ob_start();
session_start();
if(!isset($_SESSION["intLine"]))
{
$_SESSION["intLine"] = 0;
$_SESSION["strProductID"][0] = $_GET["ProductID"];
$_SESSION["strQty"][0] = 1;
header("location:show.php");
}
else
{
$key = array_search($_GET["ProductID"], $_SESSION["strProductID"]);
if((string)$key != "")
{
$_SESSION["strQty"][$key] = $_SESSION["strQty"][$key] + 1;
}
else
{
$_SESSION["intLine"] = $_SESSION["intLine"] + 1;
$intNewLine = $_SESSION["intLine"];
$_SESSION["strProductID"][$intNewLine] = $_GET["ProductID"];
$_SESSION["strQty"][$intNewLine] = 1;
}
header("location:show.php");
}
?>
PHP สร้างระบบตะกร้าสั่งซื้อสินค้า Shopping Cart ด้วย Session และ Array (PHP กับ MySQL)
|
|
|
|
|
Date :
2015-11-09 16:00:21 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|