|
 |
|
ช่วยดูหน่อยครับ ผม update ฐานข้อมูลไม่ได้อะครับ เมื่อเปลี่ยนค่าใน textbox |
|
 |
|
|
 |
 |
|
ช่วยดูโค้ดหน่อยครับ ผมส่งค่าไป มันไม่อัพเดทฐานข้อมูลให้ครับ
หน้า chkorderdetail.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>BKK SHOP</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript" src="js/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="js/addcart.js"></script>
</head>
<body>
<?
include("sql/connect.php");
if($_POST["Mode"]=="delete"){
$sql="delete from orderdetail where sess_id='".$_POST['sess_id']."' and p_id = '".$_POST['p_id']."' ";
@mysql_query($sql) or die(mysql_error());
}
if($_POST["Mode"]=="update"){
$sql="select * from product where p_id='".$_POST["p_id"]."'";
$query=@mysql_query($sql) or die(mysql_error());
$objresult=mysql_fetch_array($query);
$money=$objresult["p_price"]*$_POST["qty"];
$strSQL = "UPDATE orderdetail SET ";
$strSQL .="quantity = '".$_POST["qty"]."' ";
$strSQL .=",money = '".$money."' ";
$strSQL .="WHERE p_id = '".$_POST["p_id"]."' and sess_id='".$_POST["sess_id"]."' ";
$objQuery = mysql_query($strSQL);
}
$sql="select * from orderdetail where sess_id='".$_SESSION["sess_userid"]."'";
$result=@mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($result)!=0){
?>
<table width="603" height="73" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="302" align="left">ชื่อสินค้า</td>
<td width="79" align="center">จำนวน</td>
<td width="76" align="center">ราคา/ชิ้น</td>
<td width="83" align="center">รวมราคา</td>
<td width="63" align="center">ลบ</td>
</tr>
<?
while($objResult = mysql_fetch_array($result))
{
$sql1="select * from product where p_id='".$objResult["p_id"]."'";
$result1=@mysql_query($sql1) or die(mysql_error());
while($objResult1 = mysql_fetch_array($result1))
{
$i=$i+1;
$total=$objResult1["p_price"]*$objResult["quantity"];
$sum=$sum+$total;
?>
<tr>
<td align="left"><?=$objResult1["p_name"];?></td>
<td align="center"><label>
<input name="qty<?=$i;?>" type="text" id="qty<?=$i;?>" size="10" value="<?=$objResult["quantity"];?>" onchange="JavaScript:updatecart('qty<?=$i;?>','<?=$objResult["p_id"];?>','<?=$_SESSION["sess_userid"];?>','update');"/>
</label></td>
<td align="center"><?=$objResult1["p_price"];?></td>
<td align="center"><?=$total;?></td>
<td align="center"><label>
<input type="image" name="imageField" id="imageField" src="img/del.jpg" onclick="delcart('<?=$objResult["p_id"];?>','<?=$_SESSION["sess_userid"];?>','delete')"/>
</label></td>
</tr>
<?
}
}
?>
<tr>
<td height="26" align="right">รวมทั้งหมด </td>
<td align="right"> </td>
<td align="center"> </td>
<td align="center"><?=$sum;?></td>
<td align="center"><label>
<input type="submit" name="button" id="button" value="Update" />
</label></td>
</tr>
</table>
<? }else { ?>
ยังไม่มีสินค้าในตระกร้า
<? } ?>
</body>
</html>
หน้า addcart.js
function updatecart(qty,pid,sessid,Mode){
var url='chkorder_detail.php';
var pmeters = "qty=" + qty+ "p_id=" + pid+ "&sess_id=" + sessid+ "&Mode=" + Mode;
xmlhttp = newXmlHttp();
xmlhttp.open('POST',url,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length",pmeters.length);
xmlhttp.setRequestHeader("Connection","close");
xmlhttp.send(pmeters);
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState == 3){
document.getElementById("Cart").innerHTML="Now is Loading...";
}
if(xmlhttp.readyState == 4){
document.getElementById("Cart").innerHTML=xmlhttp.responseText;
location.reload();
}
}
window.location.reload();
}
Tag : PHP, MySQL, Ajax, CakePHP

|
|
 |
 |
 |
 |
Date :
2014-03-22 23:42:35 |
By :
กล้า |
View :
701 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$objQuery = mysql_query($strSQL) or die(mysql_error());
เอา Error มาดูครับ
|
 |
 |
 |
 |
Date :
2014-03-23 07:18:53 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อืม...ว่าแต่ใช้ session แล้วตัว session_start(); อยู่ที่ไหนครับ
|
 |
 |
 |
 |
Date :
2014-03-23 07:19:30 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันไม่ขึ้น error ครับ session_start(); อยู่หน้าที่ include ไฟล์นี้ไปครับ
|
 |
 |
 |
 |
Date :
2014-03-23 11:32:02 |
By :
กล้า |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง Code (PHP)
echo $_POST["Mode"]
แล้วได้ update ออกมาหรือเปล่าครับ 
ลอง echo $sql="delete from orderdetail where sess_id='".$_POST['sess_id']."' and p_id = '".$_POST['p_id']."' ";
ด้วยครับ เผื่อพลาด
|
 |
 |
 |
 |
Date :
2014-03-23 12:07:10 |
By :
iieszz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองแล้วครับ ค่ามันไม่ส่งมาอะครับ
|
 |
 |
 |
 |
Date :
2014-03-23 13:56:45 |
By :
กล้า |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|