มีปัญหาเกี่ยวกับ php mysql ครับ ช่วยดูหน่อย

เริ่มโดย martza125, 08 กรกฎาคม 2014, 21:23:48

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

martza125

<?php
session_start
();
$formid = isset($_SESSION['formid']) ? $_SESSION['formid'] : "";
if (
$formid != $_POST['formid']) {
echo "E00001!! SESSION ERROR RETRY AGAINT.";
} else {
unset($_SESSION['formid']);
if ($_POST) {
require 'connect.php';
for ($i 0$i count($_POST['qty']); $i++) {
$order_detail_quantity mysql_real_escape_string($_POST['qty'][$i]);
$product_id mysql_real_escape_string($_POST['product_id'][$i]);
$productcheck mysql_query("SELECT * FROM products where id = '$product_id'");
$checklow $productcheck['product_stock'] - $order_detail_quantity;
if ($checklow 1) {
header('location:index.php?a=order');
mysql_close();
exit();
}
}
$order_fullname mysql_real_escape_string($_POST['order_fullname']);
$order_address mysql_real_escape_string($_POST['order_address']);
$order_phone mysql_real_escape_string($_POST['order_phone']);

$meSql "INSERT INTO orders (order_date, order_fullname, order_address, order_phone) VALUES (NOW(),'{$order_fullname}','{$order_address}','{$order_phone}') ";
$meQeury mysql_query($meSql);
if ($meQeury) {
$order_id mysql_insert_id();
for ($i 0$i count($_POST['qty']); $i++) {
$order_detail_quantity mysql_real_escape_string($_POST['qty'][$i]);
$order_detail_price mysql_real_escape_string($_POST['product_price'][$i]);
$product_id mysql_real_escape_string($_POST['product_id'][$i]);
$lineSql "INSERT INTO order_details (order_detail_quantity, order_detail_price, product_id, order_id) ";
$lineSql .= "VALUES (";
$lineSql .= "'{$order_detail_quantity}',";
$lineSql .= "'{$order_detail_price}',";
$lineSql .= "'{$product_id}',";
$lineSql .= "'{$order_id}'";
$lineSql .= ") ";
mysql_query($lineSql);
mysql_query("UPDATE products SET product_stock = product_stock - '$order_detail_quantity' where id = $product_id"); //ตัดสต๊อก
}
mysql_close();
unset($_SESSION['cart']);
unset($_SESSION['qty']);
header('location:index.php?a=order');
}else{
mysql_close();
header('location:index.php?a=orderfail');
}
}
}
?>


ตรงส่วนที่เช็ตสต๊อกสินค้า มันดึงไม่ออกอ่ะครับ อยากให้มันเช๊คก่อนจะเกิด order

xvlnw.com

น่าจะหมายถึงตรงนี้นะครับ


<?php
$productcheck 
mysql_query("SELECT * FROM products where id = '$product_id'");
$checklow $productcheck['product_stock'] - $order_detail_quantity;
?>



คือว่า ใช้คำสั่ง Query (mysql_query) เฉยๆ มันยังไม่ออกครับ ต้อง Fetch ข้อมูลด้วยครับ (mysql_fetch_array, mysql_fetch_assoc, mysql_fetch_object)
[direct=https://cloudhost.in.th/wordpress-hosting]ツ ⓌⓄⓇⒹⓅⓇⒺⓈⓈ ⒽⓄⓈⓉⒾⓃⒼ [/direct] :wanwan014:  :D
[direct=https://cloudhost.in.th/cloudhosting.html]Cloud Hosting[/direct] [direct=https://cloudhost.in.th/cloudvps.html]Cloud Server[/direct] [direct=https://cloudhost.in.th/vpshosting.html]Cloud VPS Hosting[/direct] [direct=https://cloudhost.in.th/windowsvps.html]Cloud Windows[/direct] Tel: 080-348-0843 LINE: ixvlnw

martza125

อื้อหือ สงสัยนอนน้อยจนมึน อ๊ากกกก  :'(