|
|
|
รบกวน ดูโค็ดให้หน่อยครับ ผมอยาก ให้แสดงข้อมูลการสั่งซื้อสินค้าออกมาเป็น messagebox ยืนยัน ก่อนสั่งซื้ออะครับ และก็ถ้าผมจะตัดสต็อก ต้องส่วนไหนของโค็ดหรอครับ |
|
|
|
|
|
|
|
Code (PHP)
<code><?php require_once('Connections/db_rice.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
function check_product($var)
{
if(isset($var['chk_product']))return($var['chk_product'] == "on");
return;
}
;
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
//echo '<pre>';
//var_dump($_POST['product']);
//echo '<pre>';
mysql_select_db($database_db_rice, $db_rice);
$query_max = "SELECT MAX(OrderId) AS `maxid`,MAX(BillNumber) AS `maxnumber` FROM `order`";
$max_rows = mysql_query($query_max, $db_rice) or die(mysql_error());
$max_row_Record = mysql_fetch_assoc($max_rows);
$order_id =$max_row_Record['maxid']+1;
$order_number = $max_row_Record['maxnumber']+1;
//echo $order_id;
//echo'<br>';
//echo $order_number;
//echo'<br>';
//echo date("d/m/Y");
//echo'<br>';
//echo $_SESSION['MM_Userid'];
//echo'<br>';
//var_dump(array_filter($_POST['product'],"check_product"));
$total_price = 0;
foreach(array_filter($_POST['product'],"check_product") as &$item) {
$total_price=$total_price+($item['quantity']*$item['price']);
//var_dump($total_price);
}
//echo'<br>';
//var_dump($total_price);
$insertSQL = sprintf("INSERT INTO `order` (`OrderId`, `User_id`, `BillNumber`, `Date`, `TotalPriceAll`, `StatusID`, `DatePayment`) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($order_id, "int"),
GetSQLValueString($_SESSION['MM_Userid'], "int"),
GetSQLValueString($order_number, "int"),
GetSQLValueString(date("Y-m-d"), "date"),
GetSQLValueString($total_price, "int"),
GetSQLValueString(2, "int"),
GetSQLValueString(date("Y-m-d"), "date"));
mysql_select_db($database_db_rice, $db_rice);
$Result1 = mysql_query($insertSQL, $db_rice) or die(mysql_error());
foreach(array_filter($_POST['product'],"check_product") as &$item) {
$insertSQL = sprintf("INSERT INTO `orderdetail` (`ProductId`, `OrderId`, `Quantiy`, `Price`, `TotalPrice`) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($item['product_id'], "int"),
GetSQLValueString($order_id, "int"),
GetSQLValueString($item['quantity'], "int"),
GetSQLValueString($item['price'],"int"),
GetSQLValueString($item['quantity']*$item['price'], "int"));
mysql_select_db($database_db_rice, $db_rice);
$Result1 = mysql_query($insertSQL, $db_rice) or die(mysql_error());
}
}
mysql_select_db($database_db_rice, $db_rice);
$query_Recordset1 = "SELECT * FROM product";
$Recordset1 = mysql_query($query_Recordset1, $db_rice) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_select_db($database_db_rice, $db_rice);
$query_Recordset2 = "SELECT * FROM `order`";
$Recordset2 = mysql_query($query_Recordset2, $db_rice) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="templates/main.css"/>
<style type="text/css">
.content1 { padding: 10px 0;
width: 80%;
float: left;
text-align: center;
}
.container .content .content1 center #form1 h1 {
font-size: 100%;
font-family: Verdana, Geneva, sans-serif;
}
</style>
<title>Rice Mart</title>
</head>
<body>
<div class="container">
<?php require_once("templates/header.inc.php")?>
<?php require_once("templates/sidenav2.inc.php")?>
<div class="content">
<div class="content1"action="" >
<center>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<h1>ซื้อสินค้า</h1>
<h3>ชื่อผู้สั่งซื้อสินค้า : <?php echo $_SESSION['MM_Username']; ?></h3>
<p>วันที่สั่งสินค้า : <?php echo date("d/m/Y"); ?></p>
<p> </p>
<table border="1">
<tr>
<td>เลือกสินค้า</td>
<td><code>รหัสสินค้า</code></td>
<td><code>ชื่อสินค้า</code></td>
<td><code>ชื่อพันธุ์ข้าว</code></td>
<td><code>ราคา</code></td>
<td><code>รูปภาพ</code></td>
<td>จำนวนสินค้า</td>
</tr>
<?php
$a=0;
do { ?>
<tr>
<td><input name="<?php echo "product[".$a."][chk_product]";?>" type="checkbox" /></td>
<td><?php echo $row_Recordset1['ProductId']; ?>
<input name="<?php echo "product[".$a."][product_id]";?>" type="hidden" id="ProductId" value="<?php echo $row_Recordset1['ProductId']; ?>" /></td>
<td><?php echo $row_Recordset1['ProductName']; ?></td>
<td><?php echo $row_Recordset1['RiceSeeDid']; ?></td>
<td><?php echo $row_Recordset1['price']; ?></td>
<input name="<?php echo "product[".$a."][price]";?>" type="hidden" id="ProductId" value="<?php echo $row_Recordset1['price']; ?>" /></td>
<td><img src ="/DW-DBrice/InsertData/img-products/<?php echo $row_Recordset1['Productimg']; ?>" alt="" width="100" height="100" /></td>
<td><input name="<?php echo "product[".$a."][quantity]";?>" type="text" value="0" placeholder="จำนวนสินค้า"style="text-align:right;padding-right:2px;"/>
กระสอบ</td>
</tr>
<?php
$a+=1;
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<input name="OrderId" type="hidden" id="OrderId" value="<?php echo $row_Recordset2['OrderId']; ?>" />
<br />
<center>
<input type="submit" name="kuy" id="kuy" value="เพิ่มสินค้า" onClick="return confirm('ราคารวมสินค้าที่ท่านซื้อคือ '+<?php echo $total_price ?>+' บาท ท่านต้องการจะสั่งซื้อหรือไม่')"/>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</center>
</div>
</div>
<?php require_once("templates/footer.inc.php")?>
</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
mysql_free_result($Recordset2);
?>
</code>
Tag : HTML, HTML5, jQuery, Appserv
|
|
|
|
|
|
Date :
2017-06-14 17:10:02 |
By :
bassnaruto |
View :
909 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เคยแนะนำไปแล้วนะครับ ใช้ Dreamweaver เขียน Code PHP ไปต่อลำบากมากครับ
|
|
|
|
|
Date :
2017-06-15 23:11:47 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|