|
|
|
action ผิดครับ มันบอกว่าหาไม่เจอ ผมต้องแก้หรือเพิ่มอะไร ตรงไหน ขอคำแนะนำหน่อยครับ |
|
|
|
|
|
|
|
หา action ไม่เจอครับ
อันนี้คือโค็ดทั้งหมดครับ ช่วยแนะนำ หน่อยครับ ผมแก้มาหลายวันล่ะ แก้ได้จะได้แก้เป็นของตัวเองครับ
Code (PHP)
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
?>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(ProductID,Qty) {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'AjaxPHPShoppingCart2.php';
var pmeters = "tProductID=" + ProductID+
"&tQty=" + Qty;
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
document.getElementById('mySpan').innerHTML = HttPRequest.responseText;
}
}
}
function CheckOut()
{
window.location = 'AjaxPHPShoppingCart3.php';
}
</script>
</head>
<body onLoad="JavaScript:doCallAjax('','')">
<h1>My Cart </h1>
<table width="680" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="234" valign="top">
<?php
$objConnect = mysql_connect("localhost","root","usbw") or die("Error Connect to Database");
$objDB = mysql_select_db("peet");
$strSQL = "SELECT * FROM product ORDER BY ProductID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
echo"<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\"><tr>";
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
echo "<td>";
?>
<img src="product/<?php echo $objResult["Picture"];?>" width="70" height="61" border="0">
<center>
<?php echo $objResult["ProductName"];?>
<br>
<?php echo $objResult["Price"]." Baht";?>
<br>
<input type="text" id="txt<?php echo $intRows;?>" value="" style="width:20px">
<input type="button" value="Add" onClick="JavaScript:doCallAjax('<?php echo $objResult["ProductID"];?>',document.getElementById('txt<?php echo $intRows;?>').value);">
</center>
<?php
echo"</td>";
if(($intRows)%2==0)
{
echo"</tr>";
}
else
{
echo "<td>";
}
}
echo"</tr></table>";
?>
<?php
mysql_close($objConnect);
?>
</td>
<td width="446" valign="top"><span id="mySpan"></span></td>
</tr>
</table>
</body>
</html>
Code (PHP)
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
session_start();
$strProductID = $_POST["tProductID"];
$strQty = $_POST["tQty"];
$objConnect = mysql_connect("localhost","root","usbw") or die("Error Connect to Database");
$objDB = mysql_select_db("peet");
if($strProductID != "" and $strQty != "")
{
$strSQL = "INSERT INTO cart ";
$strSQL .="(SID,ProductID,Qty) ";
$strSQL .="VALUES ";
$strSQL .="('".session_id()."','".$strProductID."','".$strQty."') ";
$objQuery = mysql_query($strSQL);
}
?>
<center>
<h1>Your Cart</h1>
<table width="408" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="51"><div align="center">ID</div></td>
<td width="154" height="26"><div align="center">Product</div></td>
<td width="69"><div align="center">Price</div></td>
<td width="57"><div align="center">Qty</div></td>
<td width="65"><div align="center">Total</div></td>
</tr>
<?php
$intSumTotal = 0;
$intRows = 0;
$strSQL = "SELECT * FROM cart WHERE SID = '".session_id()."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
$intRows ++;
//*** Product ***//
$strSQL = "SELECT * FROM product WHERE ProductID = '".$objResult["ProductID"]."' ";
$objQueryPro = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResultPro = mysql_fetch_array($objQueryPro);
$intTotal = $objResult["Qty"] * $objResultPro["Price"];
$intSumTotal = $intSumTotal + $intTotal;
?>
<tr>
<td><div align="center"><?php echo $intRows;?></div></td>
<td><?php echo $objResultPro["ProductName"];?></td>
<td><div align="right"><?php echo number_format($objResultPro["Price"],2);?></div></td>
<td><div align="center"><?php echo $objResult["Qty"];?></div></td>
<td><div align="right"><?php echo number_format($intTotal,2);?></div></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4"><div align="right">Total Amount </div></td>
<td>
<div align="right"><?php echo number_format($intSumTotal,2);?></div></td>
</tr>
</table>
<?php
if($intSumTotal > 0)
{
?>
<br><input name="btnCheckOut" type="submit" id="btnCheckOut" value="Check Out" onClick="JavaScript:CheckOut();">
<?php
}
?>
</center>
หน้านี้ครับที่หา Action ไม่เจอครับ ผมต้องแก้ตรงไหน แนะนำหน่อยครับ
Code (PHP)
<?php
session_start();
$objConnect = mysql_connect("localhost","root","usbw") or die("Error Connect to Database");
$objDB = mysql_select_db("peet");
if($_GET["Action"]=="Save")
{
//*** Insert Order Header ***//
$strSQL = "INSERT INTO cusorder ";
$strSQL .="(Name,Email,Address,OrderDate) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtName"]."','".$_POST["txtEmail"]."','".$_POST["txtAddress"]."','".date("Y-m-d H:i:s")."') ";
$objQuery = mysql_query($strSQL);
$intOrderID = mysql_insert_id();
//*** Update Order Detail ***//
$strSQL = "UPDATE cart SET OrderID = '".$intOrderID."' ,SID = '' WHERE SID = '".session_id()."' ";
$objQuery = mysql_query($strSQL);
header("location:AjaxPHPShoppingCart4.php?OrderID=".$intOrderID);
exit();
}
?>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
<center>
<h1>Your Cart</h1>
<table width="408" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="51"><div align="center">ID</div></td>
<td width="154" height="26"><div align="center">Product</div></td>
<td width="69"><div align="center">Price</div></td>
<td width="57"><div align="center">Qty</div></td>
<td width="65"><div align="center">Total</div></td>
</tr>
<?php
$intSumTotal = 0;
$intRows = 0;
$strSQL = "SELECT * FROM cart WHERE SID = '".session_id()."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
$intRows ++;
//*** Product ***//
$strSQL = "SELECT * FROM product WHERE ProductID = '".$objResult["ProductID"]."' ";
$objQueryPro = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResultPro = mysql_fetch_array($objQueryPro);
$intTotal = $objResult["Qty"] * $objResultPro["Price"];
$intSumTotal = $intSumTotal + $intTotal;
?>
<tr>
<td><div align="center"><?php echo $intRows;?></div></td>
<td><?php echo $objResultPro["ProductName"];?></td>
<td><div align="right"><?php echo number_format($objResultPro["Price"],2);?></div></td>
<td><div align="center"><?php echo $objResult["Qty"];?></div></td>
<td><div align="right"><?php echo number_format($intTotal,2);?></div></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4"><div align="right">Total Amount </div></td>
<td>
<div align="right"><?php echo number_format($intSumTotal,2);?></div></td>
</tr>
</table>
<br>
<br>
<br>
<form action="AjaxPHPShoppingCart3.php?Action=Save" method="post" name="frmMain" id="frmMain">
<table width="408" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="127">Name</td>
<td width="275"><input name="txtName" type="text" id="txtName"></td>
</tr>
<tr>
<td>Email</td>
<td><input name="txtEmail" type="text" id="txtEmail"></td>
</tr>
<tr>
<td>Address</td>
<td><textarea name="txtAddress" id="txtAddress"></textarea></td>
</tr>
</table>
<br>
<input name="btnSave" type="submit" id="btnSave" value="Save">
</form>
</center>
</body>
</html>
Code (PHP)
<?php
session_start();
$objConnect = mysql_connect("localhost","root","usbw") or die("Error Connect to Database");
$objDB = mysql_select_db("peet");
?>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
<center>
<h1>Your Cart [<?=$_GET["OrderID"];?>] </h1>
<table width="408" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="51"><div align="center">ID</div></td>
<td width="154" height="26"><div align="center">Product</div></td>
<td width="69"><div align="center">Price</div></td>
<td width="57"><div align="center">Qty</div></td>
<td width="65"><div align="center">Total</div></td>
</tr>
<?php
$intSumTotal = 0;
$intRows = 0;
$strSQL = "SELECT * FROM cart WHERE OrderID = '".$_GET["OrderID"]."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
$intRows ++;
//*** Product ***//
$strSQL = "SELECT * FROM product WHERE ProductID = '".$objResult["ProductID"]."' ";
$objQueryPro = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResultPro = mysql_fetch_array($objQueryPro);
$intTotal = $objResult["Qty"] * $objResultPro["Price"];
$intSumTotal = $intSumTotal + $intTotal;
?>
<tr>
<td><div align="center"><?php echo $intRows;?></div></td>
<td><?php echo $objResultPro["ProductName"];?></td>
<td><div align="right"><?php echo number_format($objResultPro["Price"],2);?></div></td>
<td><div align="center"><?php echo $objResult["Qty"];?></div></td>
<td><div align="right"><?php echo number_format($intTotal,2);?></div></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4"><div align="right">Total Amount </div></td>
<td>
<div align="right"><?php echo number_format($intSumTotal,2);?></div></td>
</tr>
</table>
</center>
</body>
</html>
Tag : PHP
|
ประวัติการแก้ไข 2015-01-22 13:33:38 2015-01-22 13:37:12
|
|
|
|
|
Date :
2015-01-22 13:28:10 |
By :
saikokung |
View :
889 |
Reply :
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไฟล์ข้างล่างข้อความ หน้านี้ครับที่หา Action ไม่เจอครับ ผมต้องแก้ตรงไหน แนะนำหน่อยครับ
บรรทัดที่ 6-23 ลบออกให้หมด เอานี่ลงไปเทสก่อนครับ
Code (PHP)
<?=$_GET('Action')?>
ดูซิว่ากดแล้วมีอะไรออกมามั้ย . . .
|
|
|
|
|
Date :
2015-01-22 14:54:40 |
By :
meannerss |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
session_start();
print_r($_REQUEST);
print_r($_SESSION);
exit;
?>
ผมจะทดสอบ ต้วยคำสั่งข้างบนครับ ว่ามี request อะไรส่งมา หรือ session มีอะไรอยู่บ้าง
|
ประวัติการแก้ไข 2015-01-22 15:01:41
|
|
|
|
Date :
2015-01-22 15:01:24 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมลอง เอา <?=$_GET('Action')?> ไปใส่แทนแล้วครับ แล้ว ลบบรรทัด 6-23 ออก มัน error ครับ รันไม่ได้เลย
|
|
|
|
|
Date :
2015-01-22 16:11:50 |
By :
saikokung |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
session_start();
$objConnect = mysql_connect("localhost","root","usbw") or die("Error Connect to Database");
$objDB = mysql_select_db("peet");
if(isset($_GET["Action"]) AND $_GET["Action"]=="Save")
{
//*** Insert Order Header ***//
$strSQL = "INSERT INTO cusorder ";
$strSQL .="(Name,Email,Address,OrderDate) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtName"]."','".$_POST["txtEmail"]."','".$_POST["txtAddress"]."','".date("Y-m-d H:i:s")."') ";
$objQuery = mysql_query($strSQL);
$intOrderID = mysql_insert_id();
//*** Update Order Detail ***//
$strSQL = "UPDATE cart SET OrderID = '".$intOrderID."' ,SID = '' WHERE SID = '".session_id()."' ";
$objQuery = mysql_query($strSQL);
header("location:AjaxPHPShoppingCart4.php?OrderID=".$intOrderID);
exit();
}
?>
|
|
|
|
|
Date :
2015-01-22 16:28:27 |
By :
pgm |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หายแล้วครับ ขอบคุณพี่ๆ มากเลย มากเลย ครับ
|
|
|
|
|
Date :
2015-01-22 16:43:11 |
By :
saikokung |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้ XAMPP ป่ะ....ถ้าใช่มันจะเป็นแบบนี้ล่ะ มันไม่รู้ว่าตัวแปร คืออะไร เพิ่ม code ไว้ น่าจะหาย
if(isset($_GET['Action'])) {
$_GET['Action'];
} else {
$_GET['Action'] = '';
}
|
|
|
|
|
Date :
2015-01-23 07:43:02 |
By :
apisitp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|