Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > JavaScript โค้ดมีปัญหาเรื่องการสั่งซื้อ พอจะใส่จำนวนที่จะซื้อ มันขึ้นว่าสินค้าหมดตลอดเลย



 

JavaScript โค้ดมีปัญหาเรื่องการสั่งซื้อ พอจะใส่จำนวนที่จะซื้อ มันขึ้นว่าสินค้าหมดตลอดเลย

 



Topic : 068010



โพสกระทู้ ( 19 )
บทความ ( 0 )



สถานะออฟไลน์




Code หน้าให้เลือกซื้อสินค้า
<html>
<head>
<title>Unicity</title>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<script language="javascript">
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}
</script>
<style>
BODY <?php

include "dbconfig.php";
conndb();
$sqltxt = "SELECT * FROM product"; 
$result = mysql_query ( $sqltxt, $conn ); 
$rs = mysql_fetch_array ( $result );

?>



{
    FONT-FAMILY: Arial, Helvetica, sans-serif
}
</style>
</head>

<body>
<center><b><u><font size="5">หน้าแสดงรายการสินค้า</font></u></b></center><br>
<center>[ <a href="cart.php" onClick="NewWindow(this.href,'name','600','400','yes');return false">ตะกร้าสินค้า</a> ] [ <a href="manageorder.php">แสดงรายการคำสั่งซื้อ</a> ]</center>
<br>

<center>



  <table width="60%" height="149" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#111111" id="AutoNumber1" style="border-collapse: collapse">
 
  <tr>
   
    <td width="51%" bgcolor="#CCCCFF" align="center" height="20"><b>
    <font color="#000080">รายละเอียดสินค้า</font></b></td>
    <td width="14%" bgcolor="#CCCCFF" align="center" height="20"><b>
    <font color="#000080">สั่งซื้อ</font></b></td>
  </tr>
 
    <?
while($rs = mysql_fetch_array($result))
{
?>
  <tr>
    
<td width="51%" align="center" height="128">
    <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0" bordercolor="#111111" id="AutoNumber2" style="border-collapse: collapse">
    

      <tr>
        <td colspan="3" align="left"><strong><font size="3" color="#800000">
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;รหัสสินค้า</font> <font size="4" color="#800000">:</font><font size="3" color="#000080"><?php echo $rs["pro_id"] ?></font>          
        </strong>          
          <p><strong><font size="3" color="#800000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ชื่อสินค้า :</font>          <font size="3" color="#000080"><?php echo $rs["productName"] ?></font>
            </strong></p>
          <p>          <strong><font size="2" color="#800000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ราคา :</font><font size="2" color="#000080"> <?php echo $rs["productPrice"]  ?>&nbsp; บาท</font>
            </strong>            </p>
          <p><strong><font size="2" color="#800000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PV ต่อชิ้น :</font><font size="2" color="#000080">
            <?php echo $rs["productPV"] ?></font>
          </strong>          </p>
          <p><strong><font size="2" color="#800000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;เหลือ :</font><font size="2" color="#000080"><?php echo $rs["inventory"] ?>&nbsp; ชิ้น</font></strong></p></td>
           
      </tr>
      <br>
      </table>
    
    </td>
    
    <td width="14%" align="center" height="128"><b>
    <font color="#000080"><a href="order.php" onClick="NewWindow(this.href,'name','600','400','yes');return false">[สั่งซื้อ]</a></font></b></td>
  </tr>
<?
}
?>

</table>
</center>
<br><br>
<center></center>
</body>
</html>


Code หน้าออร์เดอร์ให้ใส่จำนวนสินค้าที่ซื้อ
<html>
<head>
<title>Unicity</title>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<style>
BODY {
    FONT-FAMILY: Arial, Helvetica, sans-serif
}
</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 bgcolor="#CCCCCC">
<?php
include("dbconfig.php");
$sqltxt = "SELECT * FROM product"; 
 $pro_id = $_GET['pro_id']; // รับรหัสสินค้าเข้ามา (ใช้แบบ GET เพราะส่งผ่าน Browser)

 if($product_id ==  $_GET['pro_id'])
 {
      $product_name =  $_GET['productName'];
      $productPV = $_GET['productPV'];
      $productPrice = $_GET['productPrice'];
      $unit = $_GET['inventory'];
    

      $product_id = $product_name." ".$productPrice." ".$productPV; // นำชื่อสินค้า , ชื่อรุ่น , รหัสสินค้า มาต่อเข้าด้วยกัน
 }
?>

<? if($unit >0) { ?>
<center>
<!-- ใส่ URL ของไฟล์ cart.php ครับ -->
<form action="cart.php" method="post" onSubmit="return checkform(this,<? echo $unit; ?>);">

<p>&nbsp;</p>
<p>
  <input name="add" type="hidden" value="<? echo $product_id; ?>">
  <input name="price" type="hidden" value="<? echo $priceperunit; ?>">
  <input type="hidden" name="product_id" value="<? echo $product_id; ?>">
  
</p>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border: 1px dashed #800000" bordercolor="#111111" width="90%" id="AutoNumber1">
  <tr>
    <td width="34%" style="border: 1px dashed #800000">
    <p align="right">จำนวนชิ้นที่จะซื้อ
    :&nbsp;&nbsp; </td>
    <td width="66%" style="border: 1px dashed #800000">&nbsp;&nbsp;<input name="qty" type="text" size="36" maxlength="5"></td>
  </tr>
  <tr>
    <td colspan="2" style="border: 1px dashed #800000">&nbsp;</td>
  </tr>
  <tr>
    <td width="100%" colspan="2" style="border: 1px dashed #800000"><center><input type="submit" value="เพิ่มลงตะกร้าสินค้า" name="submit"></center></td>
  </tr>
</table>
</form>
</center>
<? }
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>";
}
?>
</body>
</html>



มีปัญหาตรง $unit = $_GET['inventory']; คือตอนใส่จำนวนที่จะซื้อ มันขึ้นว่าสินค้าหมด
แต่ถ้าเปลี่ยนเป็น $unit = "60"; หรือเลขจำนวนเต็มอื่นๆ ก็จะสามารถซื้อได้



Tag : PHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-10-13 11:58:47 By : outlaww View : 894 Reply : 1
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ใช้ parseFloat ครอบค่าตัวแปรก่อนครับ

Go to : JavaScript ParseFloat() Convert String to Number






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-10-14 10:36:04 By : webmaster
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : JavaScript โค้ดมีปัญหาเรื่องการสั่งซื้อ พอจะใส่จำนวนที่จะซื้อ มันขึ้นว่าสินค้าหมดตลอดเลย
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่