|
 |
|
มีปัญหาคือ มันไม่ยอม insert id ของชื่อสินค้า จาก dropdownlist 2 ชั้น |
|
 |
|
|
 |
 |
|
ตอน insert มันไม่ยอมเก็บ id_product ที่เป็น id ของชื่อสินค้า ค่ะ
Code (PHP)
<? include('config.php'); ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<script language = "JavaScript">
//**** List Province (Start) ***//
function ListProvince(SelectValue)
{
frmMain.ddlProvince.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlProvince.options[frmMain.ddlProvince.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM product ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["id_category"];?>;
strValue = "<?=$objResult["id_product"];?>";
strItem = "<?=$objResult["pname"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
frmMain.ddlProvince.options[frmMain.ddlProvince.length]= myOption
}
<?
}
?>
}
//**** List Province (End) ***//
</script>
<style type="text/css">
<!--
.style42 {font-size: 12px}
.style42 {font-size: 12px}
.style33 {color: #000000; font-size: small; }
.style35 {font-weight: bold; color: #000000;}
.style41 {color: #000000; font-size: 12px; }
.style59 {font-size: 12px}
.style59 {font-size: 12px}
-->
</style>
</head>
<form name="frmMain" action="" method="post">
<table width="235" border="0">
<tr>
<td width="97"><span class="style42">ประเภทสินค้า :</span></td>
<td width="128"><select id="ddlGeo" name="ddlGeo" onChange = "ListProvince(this.value)">
<option selected value=""></option>
<?
$strSQL = "SELECT * FROM category ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["id_category"];?>">
<?=$objResult["name"];?>
</option>
<?
}
?>
</select></td>
</tr>
<tr>
<td><span class="style42">ชื่อสินค้า : <span class="style35"><span class="style33"><span class="style41"><span class="style59"> </span></span></span></span><span class="style35"><span class="style33"><span class="style41"><span class="style59"> </span></span></span></span></span></td>
<td><select id="select" name="ddlProvince" style="width:120px" >
</select></td>
</tr>
</table>
</form>
</body>
</html>
Code (PHP)
<?
include('config.php');
$strSQL = ("SELECT * from orders ORDER BY id_order DESC LIMIT 1");
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{ $a=$objResult["id_order"]; $b=$a+1; }
$id_product=$_POST['ddlProvince'];
$wide=$_POST['wide'];
$long=$_POST['long'];
$quantity=$_POST['quantity'];
if(empty($id_product)||empty($wide)||empty($long)||empty($quantity)||empty($b))
{
echo"<script>alert('กรุณากรอกข้อมูลให้ครบทุกช่อง');history.back();</script>";
exit();
}
else
{
$sql="insert into detail values('','$wide','$long','$quantity','$id_product','$b')";
mysql_query($sql)or die("error=$sql");
echo"<script>alert('--บันทึกข้อมูลเรียบร้อยแล้ว--');window.location='order_add.php';</script>";
}
?>
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2012-10-10 12:04:01 |
By :
sumonrat |
View :
1067 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 05
|