  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                ถ้าผมต้องการให้ตาราง lotto_orderdetail เก็บ id ผู้ใช้งาน หรือฟิล `id` int(11) ตามตาราง 
 
ตาราง lotto_orderdetail 
 
Code (SQL) 
CREATE TABLE `lotto_orderdetail` (
  `detail_id` int(10) NOT NULL,
  `order_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `product_qty` int(11) NOT NULL,
  `id` int(11) NOT NULL,
  `product_name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `total` float NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  
 
ตาราง lotto_login 
 
Code (SQL) 
CREATE TABLE `lotto_login` (
  `id` int(11) UNSIGNED NOT NULL,
  `first_name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `last_name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `password` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `hash` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
  `active` tinyint(1) NOT NULL,
  `login_status` enum('0','99','999') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
 
ผมลอง โดย 
ไฟล์ saveorder.php 
Code (PHP) 
<?php
     error_reporting( error_reporting() & ~E_NOTICE );
     //Set ว/ด/ป เวลา ให้เป็นของประเทศไทย
    date_default_timezone_set('Asia/Bangkok');
 	$order_name = $_POST["order_name"];
  $order_lastname = $_POST["order_lastname"];
 	$order_addr = $_POST["address"];
 	$order_email = $_POST["order_email"];
 	$order_phone = $_POST["order_phone"];
 	$p_qty = $_POST["product_qty"]; //จำนวน
  $total = $_POST['total'];
  $have = $_POST['item'];
	$order_date = date("Y-m-d H:i:s"); // วันที่ ปี เดือน วัน
 	$order_status = 1;
 	//บันทึกการสั่งซื้อลงใน order_detail
 	mysqli_query($conn, "BEGIN");
 	$query1	= "INSERT  INTO lotto_order VALUES(null,
 	'$order_name',
  '$order_lastname',
 	'$order_addr'	,
 	'$order_email',
 	'$order_phone',
 	'$order_status',
  '$order_date'
 	)";
 	$result1	= mysqli_query($conn, $query1) or die ("Error in query: $query1 " . mysql_error());
 	//ฟังก์ชั่น MAX() จะคืนค่าที่มากที่สุดในคอลัมน์ที่ระบุ ออกมา หรือ่า ใช้สำหรับหาค่าที่มากที่สุด
 	$query2 = "SELECT MAX(order_id) AS order_id FROM lotto_order  WHERE order_phone='$order_phone'";
 	$result2	= mysqli_query($conn, $query2);
 	$row = mysqli_fetch_array($result2);
 	$order_id = $row['order_id'];
  //loop
 	foreach($_SESSION['shopping_cart'] as $p_id=>$p_qty)	{
    // echo $p_id;
 		$query3	= "SELECT * FROM lotto_product WHERE product_id='$p_id'";
 		$result3 = mysqli_query($conn, $query3);
 		$row3 = mysqli_fetch_array($result3);
 		$total=$row3['product_price']*$p_qty;
    $product_name = $row3['product_name'];
///////////////////////////////////////////////เเก้ไขตรงนี้ ////////////////////////////////////////////////////////
    $queryxs = "SELECT * FROME lotto_login WHERE id ='$member_id'"; //ลอง ดึงข้อมูล lotto_login มา
    $resultxs = mysqli_query($conn, $queryxs);
    $rowxs = mysqli_fetch_array($resultxs);
    $member_id = $rowxs['id'];
    $name_login = $rowxs['email'];
 		$query4	= "INSERT INTO  lotto_orderdetail
 		values(null,
 		'$order_id',
 		'$p_id',
 		'$p_qty',
    '$member_id',  // นำมาใส่ในนี้
    '$product_name', 
 		'$total')";
 		$result4	= mysqli_query($conn, $query4);
/////////////////////////////////////////////// ////////////////////////////////////////////////////////
    $query6 = "UPDATE lotto_product SET item = item-".$p_qty." WHERE product_id = '".$p_id."'";
    $result6 = mysqli_query($conn, $query6);
 	}
  /*stock*/
 	if($result1 && $result4){
 		mysqli_query($conn, "COMMIT");
 		$msg = "บันทึกข้อมูลเรียบร้อยแล้ว ";
 		foreach($_SESSION['shopping_cart'] as $p_id)
 		{
      //unset($_SESSION['cart'][$pro_id]);
 			unset($_SESSION['shopping_cart']);
 		}
 	}
 	else{
 		mysqli_query($conn, "ROLLBACK");
 		$msg = "บันทึกข้อมูลไม่สำเร็จ กรุณาติดต่อเจ้าหน้าที่ค่ะ ";
 	}
 	// exit();
 ?>
 
 
เเต่ผลลัพธ์ คือ มันใส่ ไอดีผู้ใช้งานเป็น 0 ในฟิล id ตาราง lotto_orderdetail น่ะครับ 
เเล้วมันต้องทำยังไงเหรอครับ ถึงจะบันทึกไอดีผู้ใช้งานได้ครับ
 
 
  Tag : PHP, MySQL, MySQL, Laravel  Framework, XAMPP               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2018-02-03 15:05:31 | 
                      By :
                          AionQRy | 
                      View :
                          816 | 
                      Reply :
                          2 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  |