พอดี โปรแกรมผม add สินค้าลงตะกร้าได้แล้ว แต่พอผมกลับไปเลือกซื้อสินค้าอีกครั้งสินค้าตัวเก่าที่อยู่ในตะกร้าดันเปลี่ยนเป็นสินค้าตัวใหม่แทน สินค้าในตะกร้าไม่ยอมเพิ่มขึ้นให้ครับ ขอความกรุณาช่วยดู code ให้ทีน่ะครับ พี่ๆเพื่อนทุกคน
หน้า addcart
<?
session_start();
$id=$_GET[id];
if(count($sess_id)=="0"){
$check=1;
}else if (!in_array($id,$sess_id)){
$check=1;
}
if($check==1){
include "connect.php";
$sql="select * from tb_product where p_id='$id' ";
$result=mysql_db_query($dbname,$sql);
$rs=mysql_fetch_array($result);
$_SESSION['sess_id']=$rs[p_id];
$_SESSION['sess_name']=$rs[p_name];
$_SESSION['sess_price']=$rs[p_price];
$_SESSION['sess_type']=$rs[p_type];
$_SESSION['sess_num']=1;
}
header("Location:cart.php");
?>
หน้า cart
<?
session_start();
include "function2.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>ตระกร้าสินค้า</title>
<link href="normal_font.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style></head>
<body>
<? include "head_user.php" ?><br />
<table width="940" align="center">
<tr>
<th width="150" align="left" valign="top" scope="row"><span class="normal_font">
<? include "login_user.php"?>
</span></th>
<td align="center" valign="top">
<p>
<table width="670" border="0" cellspacing="0" cellpadding="0">
<?
$sess_id=$_SESSION['sess_id'];
$sess_name=$_SESSION['sess_name'];
$sess_price=$_SESSION['sess_price'];
$sess_type=$_SESSION['sess_type'];
$sess_num=$_SESSION['sess_num']=1;
?>
<tr>
<td align="left">
<form action="" method="post" name="calculate" id="calculate">
<?
if(count($sess_id)==0){
?>
<tr>
<td height="25" align="center"><strong><font color="#FF0000">ยังไม่มีสินค้าในตะกร้าสินค้าของท่านค่ะ</font></strong><br />
<br />
<a href="index2.php" title="เลือกซื้อสินค้า">คลิกที่นี่</a> เพื่อเลือกซื้อสินค้า </td>
</tr>
<?
}else{
?>
<table width="744" cellpadding="0" cellspacing="1" bordercolor="#FF9FAA">
<tr align="center" bgcolor="#FF9FAA" class="normal_font">
<td width="3%" height="22"><strong>ลบ</strong></td>
<td width="12%"><strong>รหัสสินค้า</strong></td>
<td width="17%"><strong>ประเภทสินค้า</strong></td>
<td width="21%"><strong>สินค้า</strong></td>
<td width="11%"><strong>จำนวน</strong></td>
<td width="21%"><strong>ราคา</strong></td>
<td width="15%" colspan="2"><strong>รวม</strong></td>
</tr>
<?php
for($i=0;$i<count($sess_id);$i++){
$total_unit=$sess_num*$sess_price;
$total=$total+$total_unit;
?>
<tr align="center">
<td><input name="id_del[]" type="checkbox" id="id_del[]" value="<?=$sess_id?>" /></td>
<td> <?=$sess_id?></td>
<td height="22"><?=$sess_type?></td>
<td><?=$sess_name?></td>
<td><input name="prd_num[]" type="text" id="prd_num[]" value="<?=$sess_num?>" size="5" maxlength="3" style="text-align:center"></td>
<td><? echo number_format($sess_price,2);?></td>
<td><? echo number_format($total_unit,2);?></td>
</tr>
<tr>
<td height="22" colspan="6" align="right"> </td>
<td colspan="2" align="center"> </td>
</tr>
<tr class="normal_font">
<td height="22" colspan="6" align="right"><strong>ราคารวมทั้งหมด</strong></td>
<td colspan="2" align="center"><strong><font color="#FF0000"><? echo number_format($total,2);?></font> บาท </strong></td>
</tr>
<tr>
<td height="22" colspan="8" align="right"> </td>
</tr>
<?
}
?>
<tr>
<td height="22" colspan="8" align="right"><input name="calculate" type="submit" id="calculate" value="คำนวณราคาสินค้า" />
<input name="continuebuy" type="button" id="continuebuy" onclick="window.location='index2.php' " value="ซื้อสินค้าต่อ" />
<input name="complete" type="submit" id="complete" value="ยืนยันสั่งซื้อสินค้า" /></td>
</tr>
<?
}
?>
</table>
</form>
</body>
</html>
หน้า index2
<?
include "function2.php";
include "connect.php";
$sql= "select * from tb_product";
$sqlquery=mysql_db_query($dbname,$sql);
?>
<!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></title>
<link href="normal_font.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style12 {font-size: 12px; font-weight: bold; }
.style23 {font-size: 14}
.style26 {font-size: 11px}
.style25 {color: #FF0000}
.style27 {color: #FF1F00}
.style30 {color: #000000}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
.style32 {color: #808080}
.style33 {
font-size: 10px;
font-weight: bold;
}
.style22 {font-size: 12px}
-->
</style>
</head>
<body>
<? include "head_user.php";?>
<br />
<table width="940" align="center" bordercolor="#FF9FAA" bgcolor="#FFFFFF">
<tr>
<th width="145" align="left" valign="top" scope="row"><p><span class="normal_font"><? include "login_user.php"?>
</span></p></th>
<th width="462" align="left" valign="top" scope="row"><table width="457" border="1" cellspacing="1" bordercolor="#FF9FAA">
<tr>
<th width="449" align="left" scope="row"><table width="232">
<tr class="normal_font">
<th width="224" height="19" align="left" bgcolor="#FF9FAA" scope="row"><strong class="normal_font style22">สินค้าของร้านค้า</strong>สวนกุหลาบ <img src="icon/update.gif" width="60" height="10" align="absmiddle" /></th>
</tr>
</table>
<p>
<?
$id=$_GET[id];
include "connect.php";
$sql = "SELECT * FROM tb_product ORDER BY p_id ";
$sqlquery = mysql_query($sql) or die ("Error Query [".sql."]");
echo"<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\"><tr>";
$intRows = 0;
while($result = mysql_fetch_array($sqlquery)) {
$id=$result['p_id'];
$code=sprintf("%05d",$id);
$name=$result['p_name'];
$detail=$result['p_detail'];
$type=$result['p_type'];
$price=$result['p_price'];
$qty=$result['p_qty'];
$img=$result['p_images'];
$intRows++;
echo "<td>";
?></p>
<table width="91" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center">
<table width="360" cellspacing="1" bordercolor="#FF9FAA">
<tr>
<th colspan="2" align="left" valign="top" bgcolor="#FF9FAA" scope="row"><a href="product/<?=$img;?>" target="_blank"></a></th>
</tr>
<tr>
<th width="140" rowspan="6" align="center" valign="top" scope="row"><a href="photo/<?=$img;?>" target="_blank"></a><a href="photo/<?=$img;?>" target="_blank"><img src="photo/<?=$img;?>" width="140" height="140" hspace="0" vspace="0" border="0" align="absbottom" /></a></th>
<td height="20" align="left" bgcolor="#FFFFFF" class="normal_font"><span class="style30"><strong>รหัสสินค้า :: <span class="style26">
<?=$code;?>
</span></strong></span></td>
</tr>
<tr>
<td width="217" height="20" align="left" bgcolor="#FFFFFF" class="normal_font"><span class="style32">ชื่อสินค้า </span>:: <span class="style26">
<?=$name;?>
</span></td>
</tr>
<tr>
<td height="20" align="left" class="normal_font"><span class="style12"><span class="style30"><span class="style32">ประเภทสินค้า</span> :: <span class="style26">
<?=$type;?>
</span></span></span></td>
</tr>
<tr>
<td height="20" align="left" class="style12"><span class="normal_font"><span class="style32">สินค้าคงเหลือ</span> :: <span class="style26">
<?=$qty;?>
</span></span></td>
</tr>
<tr>
<td height="20" align="left" class="normal_font"><strong><span class="normal_font style25"><span class="style27">ราคา :</span> <span class="style26">
<?=$price;?>
</span> <span class="style27"> บาท</span></span></strong></td>
</tr>
<tr>
<td height="20" align="right" class="normal_font"><a href="buy.php?id=<?=$id;?>"><img src="icon/Add-to-cart.gif" width="105" height="20" border="0" /></a></td>
</tr>
<tr>
<th height="14" colspan="2" align="left" valign="top" bgcolor="#FF9FAA" scope="row"><span class="style33">[ รายละเอียด ] <img src="icon/icon_promotion.gif" width="90" height="10" align="absmiddle" /></span></th>
</tr>
</table>
</div></td>
</tr>
<tr>
<td height="2"></td>
</tr>
</table>
<?
echo"</td>";
if(($intRows)%2==0)
{
echo"</tr>";
}
else
{
echo "<td>";
}
}
echo"</tr></table>";
?>
<?
mysql_close();
?>
<br />
<span class="normal_font">จำนวนสินค้ามีทั้งหมด</span><span class="normal_font style23"> <?php echo" ".mysql_num_rows($sqlquery);?> รายการ </span></th>
</tr>
</table></th>
<th width="317" align="center" valign="top" bgcolor="#FFFFFF" scope="row"> </th>
</tr>
</table>
</body>
</html>
พอดี โปรแกรมผม add สินค้าลงตะกร้าได้แล้ว แต่พอผมกลับไปเลือกซื้อสินค้าอีกครั้งสินค้าตัวเก่าที่อยู่ในตะกร้าดันเปลี่ยนเป็นสินค้าตัวใหม่แทน สินค้าในตะกร้าไม่ยอมเพิ่มขึ้นให้ครับ ขอความกรุณาช่วยดู code ให้ทีน่ะครับ พี่ๆเพื่อนทุกคน
[b]หน้า addcart[/b]
<?
session_start();
$id=$_GET[id];
if(count($sess_id)=="0"){
$check=1;
}else if (!in_array($id,$sess_id)){
$check=1;
}
if($check==1){
include "connect.php";
$sql="select * from tb_product where p_id='$id' ";
$result=mysql_db_query($dbname,$sql);
$rs=mysql_fetch_array($result);
$_SESSION['sess_id']=$rs[p_id];
$_SESSION['sess_name']=$rs[p_name];
$_SESSION['sess_price']=$rs[p_price];
$_SESSION['sess_type']=$rs[p_type];
$_SESSION['sess_num']=1;
}
header("Location:cart.php");
?>
[b]หน้า cart[/b]
<?
session_start();
include "function2.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>ตระกร้าสินค้า</title>
<link href="normal_font.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style></head>
<body>
<? include "head_user.php" ?><br />
<table width="940" align="center">
<tr>
<th width="150" align="left" valign="top" scope="row"><span class="normal_font">
<? include "login_user.php"?>
</span></th>
<td align="center" valign="top">
<p>
<table width="670" border="0" cellspacing="0" cellpadding="0">
<?
$sess_id=$_SESSION['sess_id'];
$sess_name=$_SESSION['sess_name'];
$sess_price=$_SESSION['sess_price'];
$sess_type=$_SESSION['sess_type'];
$sess_num=$_SESSION['sess_num']=1;
?>
<tr>
<td align="left">
<form action="" method="post" name="calculate" id="calculate">
<?
if(count($sess_id)==0){
?>
<tr>
<td height="25" align="center"><strong><font color="#FF0000">ยังไม่มีสินค้าในตะกร้าสินค้าของท่านค่ะ</font></strong><br />
<br />
<a href="index2.php" title="เลือกซื้อสินค้า">คลิกที่นี่</a> เพื่อเลือกซื้อสินค้า </td>
</tr>
<?
}else{
?>
<table width="744" cellpadding="0" cellspacing="1" bordercolor="#FF9FAA">
<tr align="center" bgcolor="#FF9FAA" class="normal_font">
<td width="3%" height="22"><strong>ลบ</strong></td>
<td width="12%"><strong>รหัสสินค้า</strong></td>
<td width="17%"><strong>ประเภทสินค้า</strong></td>
<td width="21%"><strong>สินค้า</strong></td>
<td width="11%"><strong>จำนวน</strong></td>
<td width="21%"><strong>ราคา</strong></td>
<td width="15%" colspan="2"><strong>รวม</strong></td>
</tr>
<?php
for($i=0;$i<count($sess_id);$i++){
$total_unit=$sess_num*$sess_price;
$total=$total+$total_unit;
?>
<tr align="center">
<td><input name="id_del[]" type="checkbox" id="id_del[]" value="<?=$sess_id?>" /></td>
<td> <?=$sess_id?></td>
<td height="22"><?=$sess_type?></td>
<td><?=$sess_name?></td>
<td><input name="prd_num[]" type="text" id="prd_num[]" value="<?=$sess_num?>" size="5" maxlength="3" style="text-align:center"></td>
<td><? echo number_format($sess_price,2);?></td>
<td><? echo number_format($total_unit,2);?></td>
</tr>
<tr>
<td height="22" colspan="6" align="right"> </td>
<td colspan="2" align="center"> </td>
</tr>
<tr class="normal_font">
<td height="22" colspan="6" align="right"><strong>ราคารวมทั้งหมด</strong></td>
<td colspan="2" align="center"><strong><font color="#FF0000"><? echo number_format($total,2);?></font> บาท </strong></td>
</tr>
<tr>
<td height="22" colspan="8" align="right"> </td>
</tr>
<?
}
?>
<tr>
<td height="22" colspan="8" align="right"><input name="calculate" type="submit" id="calculate" value="คำนวณราคาสินค้า" />
<input name="continuebuy" type="button" id="continuebuy" onclick="window.location='index2.php' " value="ซื้อสินค้าต่อ" />
<input name="complete" type="submit" id="complete" value="ยืนยันสั่งซื้อสินค้า" /></td>
</tr>
<?
}
?>
</table>
</form>
</body>
</html>
[b]หน้า index2[/b]
<?
include "function2.php";
include "connect.php";
$sql= "select * from tb_product";
$sqlquery=mysql_db_query($dbname,$sql);
?>
<!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></title>
<link href="normal_font.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style12 {font-size: 12px; font-weight: bold; }
.style23 {font-size: 14}
.style26 {font-size: 11px}
.style25 {color: #FF0000}
.style27 {color: #FF1F00}
.style30 {color: #000000}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
.style32 {color: #808080}
.style33 {
font-size: 10px;
font-weight: bold;
}
.style22 {font-size: 12px}
-->
</style>
</head>
<body>
<? include "head_user.php";?>
<br />
<table width="940" align="center" bordercolor="#FF9FAA" bgcolor="#FFFFFF">
<tr>
<th width="145" align="left" valign="top" scope="row"><p><span class="normal_font"><? include "login_user.php"?>
</span></p></th>
<th width="462" align="left" valign="top" scope="row"><table width="457" border="1" cellspacing="1" bordercolor="#FF9FAA">
<tr>
<th width="449" align="left" scope="row"><table width="232">
<tr class="normal_font">
<th width="224" height="19" align="left" bgcolor="#FF9FAA" scope="row"><strong class="normal_font style22">สินค้าของร้านค้า</strong>สวนกุหลาบ <img src="icon/update.gif" width="60" height="10" align="absmiddle" /></th>
</tr>
</table>
<p>
<?
$id=$_GET[id];
include "connect.php";
$sql = "SELECT * FROM tb_product ORDER BY p_id ";
$sqlquery = mysql_query($sql) or die ("Error Query [".sql."]");
echo"<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\"><tr>";
$intRows = 0;
while($result = mysql_fetch_array($sqlquery)) {
$id=$result['p_id'];
$code=sprintf("%05d",$id);
$name=$result['p_name'];
$detail=$result['p_detail'];
$type=$result['p_type'];
$price=$result['p_price'];
$qty=$result['p_qty'];
$img=$result['p_images'];
$intRows++;
echo "<td>";
?></p>
<table width="91" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center">
<table width="360" cellspacing="1" bordercolor="#FF9FAA">
<tr>
<th colspan="2" align="left" valign="top" bgcolor="#FF9FAA" scope="row"><a href="product/<?=$img;?>" target="_blank"></a></th>
</tr>
<tr>
<th width="140" rowspan="6" align="center" valign="top" scope="row"><a href="photo/<?=$img;?>" target="_blank"></a><a href="photo/<?=$img;?>" target="_blank"><img src="photo/<?=$img;?>" width="140" height="140" hspace="0" vspace="0" border="0" align="absbottom" /></a></th>
<td height="20" align="left" bgcolor="#FFFFFF" class="normal_font"><span class="style30"><strong>รหัสสินค้า :: <span class="style26">
<?=$code;?>
</span></strong></span></td>
</tr>
<tr>
<td width="217" height="20" align="left" bgcolor="#FFFFFF" class="normal_font"><span class="style32">ชื่อสินค้า </span>:: <span class="style26">
<?=$name;?>
</span></td>
</tr>
<tr>
<td height="20" align="left" class="normal_font"><span class="style12"><span class="style30"><span class="style32">ประเภทสินค้า</span> :: <span class="style26">
<?=$type;?>
</span></span></span></td>
</tr>
<tr>
<td height="20" align="left" class="style12"><span class="normal_font"><span class="style32">สินค้าคงเหลือ</span> :: <span class="style26">
<?=$qty;?>
</span></span></td>
</tr>
<tr>
<td height="20" align="left" class="normal_font"><strong><span class="normal_font style25"><span class="style27">ราคา :</span> <span class="style26">
<?=$price;?>
</span> <span class="style27"> บาท</span></span></strong></td>
</tr>
<tr>
<td height="20" align="right" class="normal_font"><a href="buy.php?id=<?=$id;?>"><img src="icon/Add-to-cart.gif" width="105" height="20" border="0" /></a></td>
</tr>
<tr>
<th height="14" colspan="2" align="left" valign="top" bgcolor="#FF9FAA" scope="row"><span class="style33">[ รายละเอียด ] <img src="icon/icon_promotion.gif" width="90" height="10" align="absmiddle" /></span></th>
</tr>
</table>
</div></td>
</tr>
<tr>
<td height="2"></td>
</tr>
</table>
<?
echo"</td>";
if(($intRows)%2==0)
{
echo"</tr>";
}
else
{
echo "<td>";
}
}
echo"</tr></table>";
?>
<?
mysql_close();
?>
<br />
<span class="normal_font">จำนวนสินค้ามีทั้งหมด</span><span class="normal_font style23"> <?php echo" ".mysql_num_rows($sqlquery);?> รายการ </span></th>
</tr>
</table></th>
<th width="317" align="center" valign="top" bgcolor="#FFFFFF" scope="row"> </th>
</tr>
</table>
</body>
</html>