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 > สวัสดีคะ ...ขออนุญาต ถามเรื่อง โค้ดสินค้าคงเหลือค่ะ PHP



 

สวัสดีคะ ...ขออนุญาต ถามเรื่อง โค้ดสินค้าคงเหลือค่ะ PHP

 



Topic : 121655



โพสกระทู้ ( 25 )
บทความ ( 0 )



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




สวัสดีค่ะ

คือแบบว่า ดิฉันได้ทำการเพิ่มจำนวนสินค้าไปแล้ว จำนวน 10 ชิ้น ซึ่งลูกค้าได้สั่งซื้อสินค้านั้นๆหมดไปแล้ว 10 ชิ้นพอดี

แต่ว่าสินค้าที่หมดไปดังกล่าว ยังสามารถซื้อสินค้าได้อีกทั้งที่สินค้าหมดแล้ว และก็กลายเป็นว่า สินค้ากลายเป็นติดลบ อะค่ะ

จะเพิ่มโค้ดไปยังไงดีคะ ให้มันเหลือสินค้ากลายเป็น 0 โดยที่ไม่สามารถสั่งซื้อได้อีก


ขออนุญาตสอบถามหน่อยนะคะ ขอบคุณค่ะ

อันนี้เป็นโค้ดค่ะ


Code (PHP)
$id = $_POST['pro_id'];
$cate_id = $_POST['cate_name'];
$name_product = $_POST['pro_name'];
$product_price = $_POST['pro_price'];
$product_quantity = $_POST['pro_quantity'];
$pro_remin = $_POST['pro_remin'];
$pro_weight = $_POST['pro_weight'];
$pro_set = $_POST['set_type'];
//---------------GET----------------

$action = $_GET['action'];
$id_action = $_GET['id_action'];

//----------------------------------

if(isset($action) and isset($id_action))
{
	if($action == "delete")
	{
       /* $sql_select_product = select("select * from product_type c inner join product p on c.id_protype = p.id_protype");
        if(count($sql_select_product) == 0)
        {*/
            if(delete("product","id_product = $id_action"))
            {
            echo '<div class="alert alert-dismissible alert-warning">
                    <button type="button" class="close" data-dismiss="alert">×</button>
                    <strong>สำเร็จ!</strong> ลบข้อมูลเรียบร้อย กรุณารอสักครู่...</div>';

                echo "<script>$('html, body').animate({
                    scrollTop: $('#data-in-table').offset().top
                    }, 1000);</script>";


            echo "<script>setTimeout(function(){from_load('admin/product.php');},1500);</script>";
            }
        }
       /* else
        {
            echo '<div class="alert alert-dismissible alert-danger">
					  <button type="button" class="close" data-dismiss="alert">×</button>
					  <strong>ผิดพลาด!</strong> ไม่สามารถลบข้อมูลได้เนื่องเนื่องมีข้อมูลอ้างถึง จาก ตารางสินค้า จำนวน '.count($sql_select_product).' แถว </div>';
        }
	}*/
}
else
{

	
if(empty($name_product) or empty($product_price) or empty($product_quantity) or empty($pro_weight))
{

	echo '<div class="alert alert-dismissible alert-danger">
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>ผิดพลาด!</strong> กรุณากรอกข้อมูลให้ครบ เเล้วลองอีกครั้ง
		</div>';
}
else
{
	if(empty($id))
	{
		
			$data = array(
				"id_protype" => $cate_id,
                "name_pro" => $name_product,
                "price" => $product_price,
                "remain_num" => $product_quantity,
                "quantity" => $product_quantity,
                "weight" => $pro_weight
			);
			
			if(insert("product",$data))
			{
				echo '<div class="alert alert-dismissible alert-success">
					  <button type="button" class="close" data-dismiss="alert">×</button>
					  <strong>สำเร็จ!</strong> บันทึกข้อมูลเรียบร้อย กรุณารอสักครู่...</div>';
				echo "<script>setTimeout(function(){from_load('admin/product.php');},1500);</script>";
				
			}
			else
			{
				echo '<div class="alert alert-dismissible alert-danger">
					  <button type="button" class="close" data-dismiss="alert">×</button>
					  <strong>ผิดพลาด!</strong> เกิดข้อผิดพลาด - ไม่สามารถบันทึกข้อมูลได้</div>';
			
			}
		
	}
	else
	{
        
        
        //$sql_select_product_remain = select("select remain_num from product where id_product = $id ");
        
        //$remain_num = ($sql_select_product_remain[0]['remain_num'] + $product_quantity);
        
			$data = array(
				"id_protype" => $cate_id,
                "name_pro" => $name_product,
                "price" => $product_price,
                "remain_num" => $product_quantity,
                "quantity" => $product_quantity,
                "weight" => $pro_weight
			);
			
			if(update("product",$data,"id_product = $id"))
			{
							
			echo '<div class="alert alert-dismissible alert-success">
  			<button type="button" class="close" data-dismiss="alert">×</button>
  			<strong>สำเร็จ!</strong> แก้ไขข้อมูลเรียบร้อย กรุณารอสักครู่...</div>';

				echo "<script>$('html, body').animate({
        		scrollTop: $('#data-in-table').offset().top
    			}, 3000);</script>";

			echo "<script>setTimeout(function(){from_load('admin/product.php');},1500);</script>";
				
			}
			else
			{
				echo '<div class="alert alert-dismissible alert-danger">
  				<button type="button" class="close" data-dismiss="alert">×</button>
  				<strong>ผิดพลาด!</strong> เกิดข้อผิดพลาด - ไม่สามารถบันทึกข้อมูลได้</div>';
			
			}
		
	}
}
}

?>




pg



Tag : PHP, MySQL







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2016-02-28 19:24:51 By : OK-g View : 1197 Reply : 1
 

 

No. 1



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

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

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

ง่าย ๆ เลยครับ มี Stock ก็ Where Stock > 0 เท่านั้น






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-02-29 18:07:04 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สวัสดีคะ ...ขออนุญาต ถามเรื่อง โค้ดสินค้าคงเหลือค่ะ PHP
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 อัตราราคา คลิกที่นี่