  | 
              
	              
	                
  
    
	 
        สอบถามเวลา insert ลง ฐานข้อมูลใบเสร็จครับเวลาเลือกเงินสด ให้มี order_type = 1 มันไม่เก็บให้ครับ แต่ถ้าเลือกเงินเชื่อ order_type = 2 มันเก็บให้ครับ     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                Code (PHP) 
<? ob_start(); ?>
<?php
@session_start();
mysql_connect("localhost","root","bc430");
mysql_select_db("bc430");
$cus_id = $_SESSION['cus_id'];
if($_POST['order_type']==2){
	$type=2;}
$strSQL1 = "SELECT * FROM customer WHERE cus_username = '".$_SESSION['sess_cus_username']."' ";
  $strSQL = "
	INSERT INTO orders (order_date,order_expire_transportdate,order_total,cus_id,order_transport_total,order_type)
	VALUES
	('".(date('Y')+(543).date('-m-d'))."','".(date('Y')+(543).date("-m-d", strtotime("+1 months")))."','".$_SESSION["nettotal"]."','".$_SESSION["cus_id"]."','".$_SESSION["tanprice"]."','".$type."') 
  ";;
  mysql_query($strSQL) or die(mysql_error());
  $strOrderID = mysql_insert_id();
			  
for($i=0;$i<=(int)$_SESSION["intLine"];$i++)
  {
	  if($_SESSION["strProductID"][$i] != "")
	  {
		  $queryuser = "SELECT * FROM product WHERE product_id = '".$_SESSION["strProductID"][$i]."' ";
		  $rsuser = mysql_query($queryuser)  or die(mysql_error());
		  $rowuser = mysql_fetch_array($rsuser);
		  
			   $strSQL = "
				INSERT INTO orderdetail (order_id,product_id,odertail_num,odertail_price)
				VALUES
				('".$strOrderID."','".$_SESSION["strProductID"][$i]."','".$_SESSION["strQty"][$i]."','".$_SESSION["price"][$i]."') 
			  ";
			  mysql_query($strSQL) or die(mysql_error());
	  }
  }
		
		$strSQL5 = " SELECT * FROM orderdetail 
						LEFT JOIN product ON (orderdetail.product_id = product.product_id)
								WHERE orderdetail.order_id = '".$strOrderID."' ";
					$objQuery5 = mysql_query($strSQL5) or die ("Error Query [".$strSQL5."]");
$_SESSION["strOrderID"]=$strOrderID;
header("location:finish_orderemp.php?order_id=".$strOrderID);
if($_POST['order_type']==1){
	$type=1;}
	$strSQL9 = "INSERT INTO receipt (receipt_date,receipt_total,receipt_rep,emp_id,receipt_type) VALUES 		
  	('".(date('Y')+(543).date('-m-d'))."','".$_SESSION["nettotal"]."','".(date('Y')+(543).date('-m-d'))."', '".$_SESSION['emp_id']."','".$_POST["order_type"]."')";
	mysql_query("SET NAMES UTF8");
  	mysql_query($strSQL9) or die(mysql_error());
	
	$strreceiptID = mysql_insert_id();
	
	
	
	 $strSQL = "
	INSERT INTO orders (order_date,order_expire_transportdate,order_total,cus_id,order_transport_total,order_type,receipt_id)
	VALUES
	('".(date('Y')+(543).date('-m-d'))."','".(date('Y')+(543).date("-m-d", strtotime("+1 months")))."','".$_SESSION["nettotal"]."','".$_SESSION["cus_id"]."','".$_SESSION["tanprice"]."','".$type."','".$strreceiptID."') 
  ";;
  
  mysql_query($strSQL8) or die(mysql_error());
  $strOrderID = mysql_insert_id();
  
 
  for($i=0;$i<=(int)$_SESSION["intLine"];$i++)
  {
	  if($_SESSION["strProductID"][$i] != "")
	  {
		  $queryuser = "SELECT * FROM product WHERE product_id = '".$_SESSION["strProductID"][$i]."' ";
		  $rsuser = mysql_query($queryuser)  or die(mysql_error());
		  $rowuser = mysql_fetch_array($rsuser);
		  
			  $strSQL8 = "INSERT INTO orderdetail (order_id,product_id,odertail_num,odertail_price)
				VALUES
				('".$strOrderID."','".$_SESSION["strProductID"][$i]."','".$_SESSION["strQty"][$i]."','".$_SESSION["price"][$i]."') 
			  ";
			  mysql_query($strSQL8) or die(mysql_error());
	  }
  } 
		
		$strSQL5 = " SELECT * FROM orderdetail 
						LEFT JOIN menu ON (orderdetail.product_id = product.product_id)
								WHERE orderdetail.order_id = '".$strOrderID."' ";
						$objQuery5 = mysql_query($strSQL5) or die ("Error Query [".$strSQL5."]");
						
$_SESSION["strreceiptID"]=$strreceiptID;
$_SESSION["strOrderID"]=$strOrderID;
header("location:finish_orderemp2.php?order_id=".$strOrderID);
		
unset($_SESSION["strProductID"][$i]);
unset($_SESSION["intLine"]);
unset($_SESSION["strQty"]);
  
mysql_close();
?>
<? ob_end_flush(); ?>
 
 
  Tag : PHP               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2017-06-01 11:06:02 | 
                      By :
                          jinnawat | 
                      View :
                          833 | 
                      Reply :
                          3 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 มันไม่เข้าเงื่อนไข  
 
Code (PHP) 
if($_POST['order_type']==1){
 
 
หรือว่า มันเข้า แต่มันไม่ทำงานคำสั่งนี้ ครับ 
 
Code (PHP) 
$strSQL9 = "INSERT INTO receipt (receipt_date,receipt_total,receipt_rep,emp_id,receipt_type) VALUES
('".(date('Y')+(543).date('-m-d'))."','".$_SESSION["nettotal"]."','".(date('Y')+(543).date('-m-d'))."', '".$_SESSION['emp_id']."','".$_POST["order_type"]."')";
mysql_query("SET NAMES UTF8");
mysql_query($strSQL9) or die(mysql_error());
 
 
 
หากว่ามันไม่เข้ตรงเงื่อนไข ก็ต้องเช็คค่า $_POST['order_type'] ที่ส่งมาว่ามีค่า 1 หรือ 2 ตามที่คุณตั้งไว้หรือเปล่า 
 
แต่ถ้ามันเข้าแต่คำสั่ง Insert ไม่ทำงาน คุณก็ลอง echo ค่า $strSQL9 ออกมาแล้วเอาไปรันที่ phpmyadmin ดูครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-06-01 12:09:58 | 
                        By :
                            9nonameman | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 if($_POST['order_type']==1){ //สร้างปุ๊บ
$type=1;} //ปิดปั๊บ
 
 
ไล่เปิด-ปิด เครื่องหมาย { } ดีดี if else ใช้ดีดี 
 
if($_POST['order_type']==1){ //order_type = 1
//อยากทำอะไรก็ว่าไป
}else if($_POST['order_type']==1){ //order_type = 2
//อยากทำอะไรก็ว่าไป
}else{ //order_type ไม่ใช่ 1 หรือ  2 เอาไว้กันเล่นๆ
echo "order_type ไม่ใช่ 1 หรือ  2 เอาไว้กันเล่นๆ";
}
                        
               
               | 
             
            
              
			                
  ประวัติการแก้ไข 2017-06-01 15:14:14              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-06-01 15:13:42 | 
                        By :
                            apisitp | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ไม่รู้จะเก็บวันที่ใน database เป็นปี พศ. ทำไมครับ คิวรี่ก็ยาก ต้องผ่าน หลาย function เพื่อคำนวณ 
 
เปลี่ยนแค่ตอนแสดงผลไม่ดีกว่าเหรอครับ ถ้าดูจาก database ได้โดยตรง ก็ต้องเป็นคนที่เข้าถึงได้ คงไม่ใช่ user ธรรมดา 
อธิบายด้วยปากก็น่าจะเข้าใจ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-06-01 16:14:40 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |