|
|
|
Add/Insert/Edit/Delete to MySQL On Same Form ปุ่มปันทึกหลังจากแก้ไขเสร็จ ค่าไม่แสดง |
|
|
|
|
|
|
|
เขียนโค้ด Add/Insert/Edit/Delete to MySQL On Same Form หลังจากที่เรากดปุ่มปันทึกหลังจากแก้ไขเสร็จ มันกลับหน้าเดิม แต่ค่าที่อยู่ในหน้าเดิมมันไม่แสดงค่ะ
Code (PHP)
<? include "connect.php";?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>รายการประเมิน</title>
</head>
<body bgcolor="#d4eeff">
<?
//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
$count = $_POST["count"];
$sp_code = $_POST["sp_code"];
$take = $_POST["take"];
$chk_take = $_POST["chk_take"];
$strno = $_POST["strno"];
$price = $_POST["price"];
$trandt = date("Y-m-d");
for($x=1;$x<=$count;$x++)
{
if($chk_take[$x] != "")
{
$total[$x] = $take[$x] * $price[$x];
$strSQL = "UPDATE estimate SET ";
$strSQL .="take = '".$take[$x]."' ";
$strSQL .=",total = '".$total[$x]."' ";
$strSQL .="WHERE strno = '$strno' AND sp_code = '".$sp_code[$x]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Update [".mysql_error()."]";
}
$strSQL = "SELECT * FROM estimate WHERE strno = '$strno' ";
$objQuery = mysql_query($strSQL);
while($objResult = mysql_fetch_array($objQuery))
{
$price = $objResult["price"];
$total = $objResult["total"];
$result = $result+$total;
}
$strSQL = "UPDATE estimate_mast SET ";
$strSQL .="price = '$result' ";
$strSQL .=",trandt = '$trandt' ";
$strSQL .="WHERE strno = '$strno' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Update [".mysql_error()."]";
}
}
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
$strSQL = "DELETE FROM estimate ";
$strSQL .="WHERE strno = '".$_GET["sID"]."' AND sp_code = '".$_GET["cID"]."' ";
$objQuery = mysql_query($strSQL);
$strSQL = "SELECT * FROM estimate WHERE strno = '".$_GET["sID"]."' ";
$objQuery = mysql_query($strSQL);
while($objResult = mysql_fetch_array($objQuery))
{
$price = $objResult["price"];
$total = $objResult["total"];
$result = $result+$total;
}
//echo $result;
$strSQL ="UPDATE estimate_mast SET ";
$strSQL .="price = '$result' ";
$strSQL .="WHERE strno = '".$_GET["sID"]."' ";
$objQuery = mysql_query($strSQL);
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
?>
<?
$strSQL = "SELECT * FROM estimate
INNER JOIN group_estimate ON estimate.group_no = group_estimate.group_no
WHERE strno = '".$_GET["sID"]."' ORDER BY idno ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$count = mysql_num_rows($objQuery);
?>
<div id="right_block6">
<!--TAB MENU-->
<div id="tabContaier">
<!-- //Tab buttons -->
<ul>
<li><a href="estimate01.php?sID=<?=$strno;?>&brand=<?=$brand_id;?>&class=<?=$class_id;?>">อะไหล่ใช้บ่อย</a></li>
<li><a href="estimate02.php?sID=<?=$strno;?>&brand=<?=$brand_id;?>&class=<?=$class_id;?>">ไฟ</a></li>
<li><a href="estimate03.php?sID=<?=$strno;?>&brand=<?=$brand_id;?>&class=<?=$class_id;?>">เครื่องยนต์</a></li>
<li><a href="estimate04.php?sID=<?=$strno;?>&brand=<?=$brand_id;?>&class=<?=$class_id;?>">ไฟเบอร์</a></li>
<li><a href="estimate05.php?sID=<?=$strno;?>&brand=<?=$brand_id;?>&class=<?=$class_id;?>">อื่นๆ</a></li>
<li><a href="estimate06.php?sID=<?=$strno;?>&brand=<?=$brand_id;?>&class=<?=$class_id;?>" class="active" >ดูรายการประเมิน</a></li>
</ul>
</div> <br /><br /><br>
<form name="frmMain" method="post" action="<?=$_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<table width="100%" style="font-family: Verdana, Geneva, sans-serif; font-size:12px;" cellspacing="0">
<tr align="center" bgcolor="#989898" >
<td width="12%" height="37"><b></b></td>
<td width="16%" align="left"><b>รหัสอะไหล่</b></td>
<td width="27%" align="left"><b>รายการอะไหล่</b></td>
<td width="15%" align="left"><b>เบิก/ทำสี</b></td>
<td width="11%" align="left"><b>ราคา</b></td>
<td width="9%" align="left"><b>จำนวน</b></td>
<td width="10%" align="left"><b>ราคารวม</b></td>
</tr>
<?
$x=0;
while($objResult = mysql_fetch_array($objQuery))
{
$strno = $objResult["strno"];
$sp_code = $objResult["sp_code"];
$sp_name = $objResult["sp_name"];
$chk_take = $objResult["chk_take"];
$take = $objResult["take"];
$price = $objResult["price"];
$engno = $objResult["engno"];
$group_name = $objResult["group_name"];
$result = $take * $price;
$total = $total + $result;
$x++;
if($x%2==0)
{
$bg = "#e7e7fe";
}else{
$bg = "#FFFFFF";
}
?>
<?
if($strno == $_GET["sID"] and $sp_code == $_GET["cID"] and $_GET["Action"] == "Edit")
{
?>
<tr bgcolor="<?=$bg;?>">
<td height="39">
<input style="width:55px; height:28px;" name="btnAdd" type="button" id="btnUpdate" value="บันทึก" OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();">
<input style="width:55px; height:28px;" name="btnAdd" type="button" id="btnCancel" value="ยกเลิก" OnClick="window.location='<?=$_SERVER["PHP_SELF"];?>';">
</td>
<input type="hidden" name="idno[<?=$x-1;?>]" id="idno[<?=$x-1;?>]" value="<?=$x;?>">
<td align="left"><?=$sp_code?></td>
<td align="left"><?=$sp_name?></td>
<input name="strno" type="hidden" value="<?=$strno;?>" />
<input name="sp_name[<?=$x;?>]" type="hidden" value="<?=$sp_name;?>" />
<input name="sp_code[<?=$x;?>]" type="hidden" value="<?=$sp_code;?>" />
<input name="price[<?=$x;?>]" type="hidden" value="<?=$price;?>" />
<td align="left">
<div id="radio-demo">
<input type="checkbox" name="chk_take[<?=$x;?>]" value="1" <? if( $chk_take == 1) { echo "checked"; } ?>> เบิก
<input type="checkbox" name="chk_take[<?=$x;?>]" value="2" <? if( $chk_take == 2) { echo "checked"; } ?>> ทำสี
</td>
<td><input type="text" name="price<?=$x;?>" value="<?=number_format($price, 2, '.', ', ');?>" size="8" readonly></td>
<td>
<input type="text" name="take[<?=$x;?>]" id="take<?=$x;?>" autocomplete="off"
onKeyDown="var textStatus = document.getElementById('take<?=$x;?>');
var checkStatus = document.getElementById('chk_take<?=$x;?>_1');
if(textStatus.value!='') checkStatus.checked='checked';
else if(textStatus.value =='') checkStatus.checked=''
if(this.value==0) this.value = '';"
onKeyUp="if(this.value==0) this.value=0;
document.all.total<?=$x;?>.value = (parseFloat(document.all.take<?=$x;?>.value)* <?=$price;?>) .toFixed(2);
if(document.getElementById('sum').value == '')
document.getElementById('sum').value = 0;
document.getElementById('sum').value = parseFloat(document.getElementById('sum').value)+parseFloat(document.all.total<?=$x;?>.value);"
value="<?=$take;?>"size="8">
</td>
<td><input type="text" name="total<?=$x;?>" id="total<?=$x;?>" value="<?=number_format($total,'2','.',',');?>" readonly size="8"></td>
</tr>
<?
}else
{
?>
<tr bgcolor="<?=$bg;?>">
<td height="39">
<button style="width:40px; height:28px;">
<a href="JavaScript:{window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&sID=<?=$strno;?>&cID=<?=$sp_code;?>';}">
ลบ</a></button>
<button style="width:40px; height:28px;" ><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&sID=<?=$strno;?>&cID=<?=$sp_code;?>">แก้ไข</a></button>
</td>
<input type="hidden" name="idno[<?=$x-1;?>]" id="idno[<?=$x-1;?>]" value="<?=$x;?>">
<td align="left"><?=$sp_code?></td>
<td align="left"><?=$sp_name?></td>
<input name="sp_name[<?=$x;?>]" type="hidden" value="<?=$sp_name;?>" />
<input name="sp_code[<?=$x;?>]" type="hidden" value="<?=$sp_code;?>" />
<input name="price[<?=$x;?>]" type="hidden" value="<?=$price;?>" />
<td align="left">
<div id="radio-demo">
<input type="checkbox" name="chk_take[<?=$x;?>]" value="1" <? if( $chk_take == 1) { echo "checked"; } ?> disabled readonly> เบิก
<input type="checkbox" name="chk_take[<?=$x;?>]" value="2" <? if( $chk_take == 2) { echo "checked"; } ?> disabled readonly> ทำสี
</td>
<td><input type="text" name="price<?=$x;?>" value="<?=number_format($price, 2, '.', ', ');?>" size="8" disabled readonly></td>
<td>
<input type="text" name="take[<?=$x;?>]" id="take<?=$x;?>" autocomplete="off" disabled readonly
onKeyDown="var textStatus = document.getElementById('take<?=$x;?>');
var checkStatus = document.getElementById('chk_take<?=$x;?>_1');
if(textStatus.value!='') checkStatus.checked='checked';
else if(textStatus.value =='') checkStatus.checked=''
if(this.value==0) this.value = '';"
onKeyUp="if(this.value==0) this.value=0;
document.all.total<?=$x;?>.value = (parseFloat(document.all.take<?=$x;?>.value)* <?=$price;?>) .toFixed(2);
if(document.getElementById('sum').value == '')
document.getElementById('sum').value = 0;
document.getElementById('sum').value = parseFloat(document.getElementById('sum').value)+parseFloat(document.all.total<?=$x;?>.value);"
value="<?=$take;?>"size="8">
</td>
<td><input type="text" name="total<?=$x;?>" id="total<?=$x;?>" value="<?=number_format($result,'2','.',',');?>" disabled readonly size="8"></td>
</tr>
<? } }?>
<tr bgcolor="#f0e79b">
<td height="33" colspan="3" align="center"><b>รวมรายการทั้งหมด <?=$x;?> รายการ</b></td>
<td><b>รวมราคาทั้งหมด (บาท)</b></td>
<td colspan="3" align="center"><input type="text" name="sum" id="sum" readonly size="8" value="<?=number_format($total,'2','.',',');?>"></td>
</tr>
<tr>
<td colspan="6"><input type="hidden" name="count" value="<?=$x;?>" /></td>
</tr>
</table>
</div>
</form>
</body>
Tag : PHP
|
ประวัติการแก้ไข 2013-11-14 10:02:32 2013-11-14 10:03:20
|
|
|
|
|
Date :
2013-11-14 10:01:51 |
By :
PALM26 |
View :
4006 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าเขียนโค่ด delete มันกลับมาหน้าเดิมได้ค้ะ
แต่ทำไมขอโค้ด แก้ไข ค่ามันถึงไม่มา
|
|
|
|
|
Date :
2013-11-14 13:44:57 |
By :
PALM26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตัวแปร จาก หน้าแก้ไขไม่ตรงกับหน้า query หรือป่าวครับ
|
|
|
|
|
Date :
2013-11-14 21:56:09 |
By :
topza1412 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|