|
|
|
หากเรากรอก เข้าไปเลขไม่เกินสิบ จะสามารถกรอกได้ แต่หากเรากรอกจำนวนเกิน 10 มันจะขึ้นฟ้องว่าไม่เพียงพอ ทั้งๆที่ยังมีเป็นร้อย |
|
|
|
|
|
|
|
หากเรากรอก เข้าไปเลขไม่เกินสิบ จะสามารถกรอกได้ แต่หากเรากรอกจำนวนเกิน 10 มันจะขึ้นฟ้องว่าไม่เพียงพอ ทั้งๆที่ยังมีเป็นร้อย
เป็นเพราะอะไรหรือคะ หากม่เจอจริงๆว่าเป็นเพราะอะไรคะ
Code (PHP)
<?
session_start();
ob_start();
?>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<style>
BODY {
FONT-FAMILY: Arial, Helvetica, sans-serif;
background-image: url();
background-color: #93EAFF;
}
.style38 {
font-family: AngsanaUPC;
font-size: 22px;
font-weight: bold;
}
</style>
<script language="JavaScript" type="text/javascript">
function checkform (form,units)
{
if (form.qty.value == "") {
alert( "โปรดกรอกจำนวนยาที่จ่ายด้วย" );
form.qty.focus();
return false ;
}
if (form.qty.value <= 0) {
alert( "จำนวนจำนวนยาที่จ่ายต้องมากกว่าศูนย์" );
form.qty.focus();
return false ;
}
if (form.qty.value != "") {
var val = form.qty.value;
var chars = "0123456789";
var len = val.length;
var char = "";
for (i=0; i<len; i++)
{
char = val.charAt(i);
if (chars.indexOf(char)==-1)
{
alert("จำนวนยาที่จ่ายต้องเป็นเลขจำนวนเต็มบวกเท่านั้น");
form.qty.focus();
return false;
}
}
}
if (form.qty.value > units) {
alert( "ไม่สามารถจำนวนยาที่จ่ายได้ : มีจำนวนยาที่จ่ายไม่เพียงพอ" );
form.qty.focus();
return false ;
}
return true ;
}
</script>
</head>
<body>
<?php
$preseway_id= $_GET['preseway_id'];
$store_id= $_GET['store_id']; // รับรหัสสินค้าเข้ามา (ใช้แบบ GET เพราะส่งผ่าน Browser)
$unit_drug= $_GET['unit_drug'];
require_once('connect.php');
mysql_connect($hostname,$username,$password)or die("can't connect DB");
mysql_select_db($dbname) or die("can't connect DB");
$query_goods = "SELECT * FROM store where store_id='$store_id' ;";
$goods = mysql_db_query($dbname,$query_goods) or die(mysql_error());
$row = mysql_num_rows($goods);
$i=0;
$row_goods= mysql_fetch_array($goods);
$store_name =$row_goods['store_name'];
$properties =$row_goods['properties'];
$advice =$row_goods['advice'];
$store_type =$row_goods['store_type'];
$unit_drug =$row_goods['unit_drug'];
$price =$row_goods['price'];
$stock_store =$row_goods['stock_store'];
?>
<? if($stock_store>0) { ?>
<center>
<!-- ใส่ URL ของไฟล์ cart.php ครับ -->
<form action="order.php?preseway_id=<? echo $preseway_id; ?> " method="post" onSubmit="return checkform(this,<? echo $preseway_id; ?>);">
<input name="store_name" type="hidden" value="<? echo $store_name; ?>">
<input name="price" type="hidden" value="<? echo $price; ?>">
<input type="hidden" name="store_id" value="<? echo $store_id; ?>">
<input type="hidden" name="unit_drug" value="<? echo $unit_drug; ?>">
<input name="store_id" type="hidden" value="<? echo $store_id; ?>" />
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border: 1px dashed #800000" bordercolor="#111111" width="90%" id="AutoNumber1">
<tr>
<td width="34%" background="../image/top.jpg" bgcolor="#FFFFFF" style="border: 1px dashed #800000">
<p align="right"><span class="style38">จำนวนยาที่จ่าย
:</span> </td>
<td width="66%" background="../image/top.jpg" bgcolor="#FFFFFF" style="border: 1px dashed #800000">
<input name="qty" type="text" size="36" maxlength="5">
<label>
<select name="unit_drug" id="unit_drug">
<option selected>กรุณาเลือก</option>
<option value="เม็ด">เม็ด</option>
<option value="ขวด">ขวด</option>
<option value="หลอด">หลอด</option>
<option value="ชุด">ชุด</option>
<option value="แพง">แพง</option>
<?
include("include/config.php");
$sql="select * from store order by store_id ASC";
$dbquery=mysql_db_query($db,$sql);
while($result=mysql_fetch_array($dbquery)){
if($store_id == $result[store_id]){ //เพื่อให้ แสดง $pt_id ที่ส่งค่ามาให้
?>
<?
}else{?>
<?
} }
?>
</select>
</label></td>
</tr>
<tr>
<td width="100%" colspan="2" background="../image/foot.jpg" bgcolor="#00CCFF" style="border: 1px dashed #800000"><center>
<input type="submit" value="เพิ่มลงตะกร้ายา" name="submit">
</center></td>
</tr>
</table>
</form>
</center>
<p>
<? }
else {
echo "<center>
<table border=\"1\" style=\"border-style:dotted; border-collapse: collapse; padding-left:4; padding-right:4; padding-top:1; padding-bottom:1\" bordercolor=\"#111111\" width=\"75%\" id=\"AutoNumber1\" height=\"138\">
<tr>
<td height=\"136\">
<center>
<font size=\"5\" color=\"#000080\">เพิ่มเรียบร้อยแล้ว</font><br>
</center>
</td>
</tr>
</table>
</center><br>";
}
?>
</p>
<p align="center"><?php
session_start();
mysql_db_query($db,"SET NAMES tis620");
//Create 'cart' if it doesn't already exist
if (!isset($_SESSION['SHOPPING_CART'])){ $_SESSION['SHOPPING_CART'] = array(); }
//Add an item only if we have the threee required pices of information: name, price, qty
if (isset($_POST['store_name']) && isset($_POST['price']) && isset($_POST['qty'])&& isset($_POST['unit_drug'])){
//Adding an Item
//Store it in a Array
$ITEM = array(
//Item name
'store_name' => $_POST['store_name'],
//Product id
'store_id' => $_POST['store_id'],
//Item Price
'price' => $_POST['price'],
//Qty wanted of item
'qty' => $_POST['qty'],
'unit_drug' => $_POST['unit_drug']
);
//Add this item to the shopping cart
$_SESSION['SHOPPING_CART'][] = $ITEM;
//Clear the URL variables
//header('Location: ' . $_SERVER['PHP_SELF']);
}
//Allowing the modification of individual items no longer keeps this a simple shopping cart.
//We only support emptying and removing
else if (isset($_GET['remove'])){
//Remove the item from the cart
unset($_SESSION['SHOPPING_CART'][$_GET['remove']]);
//Re-organize the cart
//array_unshift ($_SESSION['SHOPPING_CART'], array_shift ($_SESSION['SHOPPING_CART']));
//Clear the URL variables
header('Location: ' . $_SERVER['PHP_SELF']);
}
else if (isset($_GET['empty'])){
//Clear Cart by destroying all the data in the session
session_destroy();
//Clear the URL variables
header('Location: ' . $_SERVER['PHP_SELF']);
}
else if (isset($_POST['update'])) {
//Updates Qty for all items
foreach ($_POST['items_qty'] as $itemID => $qty) {
//If the Qty is "0" remove it from the cart
if ($qty == 0) {
//Remove it from the cart
unset($_SESSION['SHOPPING_CART'][$itemID]);
}
else if($qty >= 1) {
//Update to the new Qty
$_SESSION['SHOPPING_CART'][$itemID]['qty'] = $qty;
}
}
//Clear the POST variables
header('Location: ' . $_SERVER['PHP_SELF']);
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<title></title>
<script Language="Javascript">
<!--
function Conf(object) {
if (confirm("โปรดยืนยันการจ่ายยา ?") == true) {
return true;
}
return false;
}
//-->
</script>
<style>
BODY {
FONT-FAMILY: Arial, Helvetica, sans-serif;
background-image: url();
text-decoration: blink;
background-color: #93EAFF;
}
a:link {
color: #6600FF;
text-decoration: none;
}
.style7 {
color: #FFFFFF;
font-weight: bold;
font-size: large;
}
.style9 {
color: #FF0000;
font-weight: bold;
font-family: AngsanaUPC;
font-size: 22px;
}
.style46 { color: #333333;
font-weight: bold;
}
.style47 {color: #0000FF}
.style48 {
font-family: AngsanaUPC;
font-size: 22px;
}
.style52 {color: #000000; font-weight: bold; font-family: AngsanaUPC; font-size: 22px; }
.style56 {
font-family: AngsanaUPC;
color: #000000;
font-size: 36px;
}
.style58 {color: #0000FF; font-family: AngsanaUPC; font-size: 22px; }
.style59 {color: #FFFFFF; font-weight: bold; font-family: AngsanaUPC; font-size: 22px; }
.style18 {font-family: AngsanaUPC;
color: #0000FF;
font-size: 20px;
}
.style60 {font-family: AngsanaUPC; font-size: 20px; }
.style54 { font-family: AngsanaUPC;
font-weight: bold;
font-size: 22px;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
</style>
<body>
<center>
<span class="style7"><span class="style56">แสดงรายการจ่ายยา</span></span><br>
<br>
<br>
<div id="shoppingCartDisplay">
<form action="" method="post" name="shoppingcart">
<?php
mysql_db_query($db,"SET NAMES tis620");
?>
</span>
<table width="873" border="5" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" style="border-collapse: collapse; border ">
<tr>
<th width="339" background="../image/top.jpg" bgcolor="#00CCFF" style="border: 1px dotted #008000" scope="col"> <span class="style58">ชื่อยา</span></th>
<th width="151" background="../image/top.jpg" bgcolor="#00CCFF" style="border: 1px dotted #008000" scope="col"> <span class="style58">ราคาต่อหน่วย</span></th>
<th width="159" background="../image/top.jpg" bgcolor="#00CCFF" style="border: 1px dotted #008000" scope="col"> <center class="style58">
<span class="style58">จำนวน/หน่วยยา </span>
</center></th>
<th width="156" background="../image/top.jpg" bgcolor="#00CCFF" style="border: 1px dotted #008000" scope="col"> <center class="style58">
<span class="style58">รวม</span>
</center></th>
<th width="48" background="../image/top.jpg" bgcolor="#00CCFF" style="border: 1px dotted #008000" scope="col"> <center class="style58">
<span class="style58">ลบ</span>
</center></th>
</tr>
<?php
$_SESSION['total'] = 0;
//Print all the items in the shopping cart
foreach ($_SESSION['SHOPPING_CART'] as $itemNumber => $item) {
?>
<tr id="item<?php echo $itemNumber; ?>">
<td bgcolor="#FFFFCC" style="border: 1px dotted #008000"><center class="style52">
<?php echo $item['store_name']; ?>
</center></td>
<td style="border: 1px dotted #008000" bgcolor="#FFFFCC"><center class="style52"><?php echo number_format($item['price'],2,'.',','); ?></center></td>
<td style="border: 1px dotted #008000" bgcolor="#FFFFCC"><center class="style52">
<?php echo $item['qty']; ?> <?php echo $item['unit_drug']; ?>
</center></td>
<td bgcolor="#FFFFCC" style="border: 1px dotted #008000"><center class="style52"><?php echo number_format($item['qty'] * $item['price'],2,'.',','); ?></center></td>
<td bgcolor="#FFFFCC" style="border: 1px dotted #008000"><center class="style59">
<a href="?remove=<?php echo $itemNumber; ?>" class="style58">[ลบ]</a>
</center></td>
</tr>
<?php
$_SESSION['total'] += $item['qty'] * $item['price'];
}
?>
<tr id="itemtotal">
<td style="border: 1px dotted #008000" bgcolor="#dcf9ff" colspan="2" align="left"><div align="right"><span class="style52"> ราคารวม </span></div></td>
<td style="border: 1px dotted #008000" bgcolor="#dcf9ff" colspan="3"><p align="center" class="style52"><? echo number_format($_SESSION['total'],2,'.',','); ?> บาท</td>
</tr>
<tr id="vat">
<td style="border: 1px dotted #008000" bgcolor="#dcf9ff" colspan="2" align="left"><div align="right"><span class="style52"> ภาษีมูลค่าเพิ่ม (7%) </span></div></td>
<td style="border: 1px dotted #008000" bgcolor="#dcf9ff" colspan="3"><p align="center" class="style52"><? echo number_format(0.07*$_SESSION['total'],2,'.',','); ?> บาท</td>
</tr>
<tr id="total">
<td style="border: 1px dotted #008000" bgcolor="#dcf9ff" colspan="2" align="left"><div align="right"><span class="style52"> ราคารวมทั้งสิ้น </span></div></td>
<td style="border: 1px dotted #008000" bgcolor="#dcf9ff" colspan="3"><p align="center" class="style9"><? echo number_format((0.07*$_SESSION['total'])+$_SESSION['total'],2,'.',','); ?> บาท</td>
</tr>
<tr id="total">
<td colspan="5" align="left" background="../image/foot.jpg" style="border: 1px dotted #008000"><div align="center" class="style47 style48">[<span class="style47"><a href="javascript:window.close();">กลับไปเพิ่มยา</a>] - [<a href="?empty">ลบยาทุกรายการ</a>] - [<a href="confirm_order.php?preseway_id=<? echo $preseway_id; ?>" target="_blank" onClick="return Conf(this)" ?empty >ยืนยันการจ่ายยา</a>]</span></div></td>
</tr>
</table>
<?php $_SESSION['SHOPPING_CART_HTML'] = ob_get_flush(); ?>
<p>
<label></label>
<input name="button" type=button
onClick="javascript:window.close();" value="ปิดหน้าต่างนี้">
</p>
</form>
</div>
<p> </p>
</center>
</body>
</html> </p>
</body>
</html>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2012-05-01 15:35:33 |
By :
ชนท์ |
View :
1017 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
โค้ดยืดยาวอ่านไม่หมด
form.qty.value ลอง cast เป็น ตัวเลขก่อนคับ
|
|
|
|
|
Date :
2012-05-01 19:32:38 |
By :
pjgunner.com |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้ ParseFloat ในการ Cast ครับ
|
|
|
|
|
Date :
2012-05-02 06:20:03 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แบบไหนคะคุณวินและคุณเอี่ยว น้อง งง คะ
|
|
|
|
|
Date :
2012-05-02 08:51:56 |
By :
ชนท์ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|