|
 |
|
ช่วยทีคับ โค้ดตรวจสอบว่าใส่จำนวนสินค้า มากกว่าจำนวนที่มีอยู่ |
|
 |
|
|
 |
 |
|
คือ ผมจะทำการเช็คว่า ถ้าเกิดใส่จำนวนสินค้ามากกว่า จำนวนที่เลือกได้ จะได้แจ้งเตือน ว่าจำนวนสินค้ามากเกินไป ปัญหาอยู่ที่ว่า พอผมตรวจสอบตอนแรก ว่า หากไม่เลือกสินค้าเลยก็จะให้แสงข้อความเตือนว่าให้เลือกสินค้า แต่พอ เลือกสินค้าจำนวนมากเกินไป มันเช็คแค่แถวเดียว เช่น มีสินค้า 4 ชนิด ค่ามากสุดที่เลือกได้ คือ 3 แล้วถ้าเกิดเลือกสินค้าชนิดแรกไป 4 มันก้อจะแจ้งเตือนว่าเกิน แต่ในกรณีที่ ผมจะทำการเลือก สินค้าชนิดที่1 2 3 4 อย่าง ละ 1 มันไม่ทำการเช็คคับทั้งๆที่จำนวนรวมมันเกิน จะต้องทำยังไงดีครับ รบกวนด้วยคับ...
Code (PHP)
<?
session_start();
include("admin/db.php");
include("admin/function_inc.php");
$p_id=$_GET['p_id'];
$p_max=$_GET['p_max']; //จำนวนมากสุดที่เลือกได้
if(isset($_POST['Submit']))
{
$err=false;
for($i=0;$i<count($_POST['ps_id']);$i++)
{
//print($_POST['ps_id'][$i]." ".$_POST['qty'][$i]."<br />");
if($_POST['qty'][$i]<=0)
{
$err_flower=msg("<center>**โปรดใส่จำนวนดอกไม้**</center>");
$err=true;
}
else
{
$err_flower="";
$err=false;
break;
}
}
for($i=0;$i<count($_POST['ps_id']);$i++)
{
if($_POST['qty'][$i]>$p_max)
{
$err_flower=msg("<center>**จำนวนดอกไม้มากเกินไป**</center>");
$err=true;
}
}
if($_POST['ribbin']=="")
{
$err_ribbin=msg("<center>**โปรดเลือกริบบิ้น**</center>");
$err=true;
}
if($_POST['paper']=="")
{
$err_paper=msg("<center>**โปรดเลือกกระดาษ**</center>");
$err=true;
}
if(!$err)
{
$sql="select max(os_id)+1 from orderspe";
$result=mysql_query($sql, $link);
$arr=mysql_fetch_array($result);
if(is_null($arr[0]))
{
$os_id=1;
}
else
{
$os_id=$arr[0];
}
for($i=0;$i<count($_POST['ps_id']);$i++)
{
if($_POST['qty'][$i]>0)
{
$sql="insert into orderspe (os_id, ps_id, qty) values ('$os_id','".$_POST['ps_id'][$i]."', '".$_POST['qty'][$i]."')";
mysql_query($sql, $link);
}
}
$sql="insert into orderspe (os_id, ps_id, qty) values ('$os_id','".$_POST['ribbin']."', '1')";
mysql_query($sql, $link);
$sql="insert into orderspe (os_id, ps_id, qty) values ('$os_id','".$_POST['paper']."', '1')";
mysql_query($sql, $link);
header("location:shopping_cart.php?p_id=".$_GET['p_id']."&os_id=$os_id&action=buy_now");
}
}
?>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-02-14 22:11:41 |
By :
zerobuster |
View :
1261 |
Reply :
0 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 04
|