Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > มีรูป ช่วยเติมโคทให้หนูหน่อยค่ะ Cart จะข้อมูลลูกค้าลง sql ค่ะ รบกวนหน่อยค่ะ อีก สอง วันหนูส่งงานอาจารแล้ว



 

มีรูป ช่วยเติมโคทให้หนูหน่อยค่ะ Cart จะข้อมูลลูกค้าลง sql ค่ะ รบกวนหน่อยค่ะ อีก สอง วันหนูส่งงานอาจารแล้ว

 



Topic : 100337

Guest




ช่วยหน่อยนะค่ะ อีก สอง วัน ส่งแล้ว จะเก็บข้อมูลหน้านี้อะค่ะ

คือจะเก็บที่เป็นสินค้าละก็ ชื่อ ที่อยู่ เบอโทรอะค่ัะ
หหห

หหฟฟ

ช่วยเติมให้หน่อย นะค่ัะไม่รู้จะสั่งยังไงให้ไปเก็บอีก ฐานข้อมูล เวลาลูกค้ากดสั่ง อะค่ะ

Code (PHP)
<?php 
session_start(); // Start session first thing in script
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
// Connect to the MySQL database 
include "storescript/connect_to_mysql.php";
?>
<?php 
if (isset($_POST['pid'])){
	$pid = $_POST['pid'];
	$wasFound = false;
	$i = 0;
	//if the cart session variable is not set or cart arraty is empty
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1){
	//RUN IF THE CART IS EMPTY OR NOT SET
	$_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => 1));
} else {
	// RUN IF THE CART HAS AT LEAST ONE ITEM IN IT
	foreach ($_SESSION["cart_array"] as $each_item){
		$i++;
		while (list($key, $value) = each($each_item)){
			if ($key == "item_id" && $value == $pid){
				// That item is in cart already so lets adjust its quantity using array_splice()
				array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1)));
				$wasFound = true;
			}// close if condition
	 	 }// close while loop
	  }// close foreach loop
	  if ($wasFound == false){
		  array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => 1));
	  }
  }
  header("location: cart.php");
  exit();
}
?>

<?php 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//       Section 2 (if user chooses to empty their shopping cart
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart"){
	unset($_SESSION["cart_array"]);
}
?>
<?php 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//       Section 3 (if user chooses to empty their shopping cart
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset($_POST['item_to_adjust']) && $_POST['item_to_adjust'] != ""){
	//execute some code
	$item_to_adjust = $_POST['item_to_adjust'];
	$quantity = $_POST['quantity'];
	$quantity = preg_replace('#[^0-9]#i', '', $quantity); 
	if ($quantity >= 100) { $quantity = 99; }
	if ($quantity < 1) { $quantity = 1; }
	$i = 0;
	foreach ($_SESSION["cart_array"] as $each_item){
		$i++;
		while (list($key, $value) = each($each_item)){
			if ($key == "item_id" && $value == $item_to_adjust){
				// That item is in cart already so lets adjust its quantity using array_splice()
				array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $item_to_adjust, "quantity" => $quantity)));
			}// close if condition
	 	 }// close while loop
	  }// close foreach loop
	
}
?>
<?php 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//       Section 4 (if user wants to remove an item from cart)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset($_POST['index_to_remove']) && $_POST['index_to_remove'] != "") {
    // Access the array and run code to remove that array index
 	$key_to_remove = $_POST['index_to_remove'];
	if (count($_SESSION["cart_array"]) <= 1) {
		unset($_SESSION["cart_array"]);
	} else {
		unset($_SESSION["cart_array"]["$key_to_remove"]);
		sort($_SESSION["cart_array"]);
	}
}
?>

<?php 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//       Section 5 (render the cart for the user to view)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$cartOutput = "";
$cartTotal = "";
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1){
	$cartOutput = "<h2 align='center'>Your shopping cart is empty</h2>";
} else {
	$i = 0;
	foreach ($_SESSION["cart_array"] as $each_item){
		$item_id = $each_item['item_id'];
		$sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1");
		while ($row = mysql_fetch_array($sql)) {
			$product_name = $row["product_name"];
			$price = $row["price"];
			$details = $row["details"];
		}
		$pricetotal = $price * $each_item['quantity'];
		$cartTotal = $pricetotal + $cartTotal;
		// td row
		$cartOutput .= "<tr>";
		$cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_name . '</a><br /><img src="inventory_images/' . $item_id . '.jpg"  alt="' . $product_name . '" width="40" height="52" border="1" /></td>';
		$cartOutput .= '<td>'. $details . '</td>';
		$cartOutput .= '<td>'. $price . ' B.</td>';
		$cartOutput .= '<td><form action="cart.php" method="post">
		<input name="quantity" type="text" value="'. $each_item['quantity'] . '" size="1" maxlength="2" />
		<input name="adjustBtn' . $item_id . '" type="submit"  value="change" />
		<input name="item_to_adjust" type="hidden" value="' . $item_id . '" />
		</form></td>';
		//$cartOutput .= '<td>'. $each_item['quantity'] . '</td>';
		$cartOutput .= '<td>'. $pricetotal . ' B.</td>';
		$cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '" type="submit"  value="X"/><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>';
		$cartOutput .= '</tr>';
		$i++;
	}
	$cartTotal = "<div align='right'>???????????? ????  = " . $cartTotal . "B.(THAI) </div>";
}
?>





Tag : PHP, MySQL, JavaScript







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-09-11 15:10:33 By : พลอย View : 738 Reply : 1
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ดูตัวอย่างของไฟล์ save_checkout.php ครับ

PHP สร้างระบบตะกร้าสั่งซื้อสินค้า Shopping Cart ด้วย Session และ Array (PHP กับ MySQL)







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-09-12 06:09:17 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : มีรูป ช่วยเติมโคทให้หนูหน่อยค่ะ Cart จะข้อมูลลูกค้าลง sql ค่ะ รบกวนหน่อยค่ะ อีก สอง วันหนูส่งงานอาจารแล้ว
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่