ถามเรื่อง $_SERVER["PHP_SELF"]; ครับ ตอนรันแล้วมันไม่เก็บค่าที่ post ไว้
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<script>
function ClickCheckAll(vol)
{
var i=1;
for(i=1;i<=document.frmMain.hdnCount.value;i++)
{
if(vol.checked == true)
{
eval("document.frmMain.chkDel"+i+".checked=true");
}
else
{
eval("document.frmMain.chkDel"+i+".checked=false");
}
}
}
//id="chkDel<?=$i;?>"
</script>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("guide_joborder");
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
if ($_POST["txtAddAdd"]=="on"){
$addadd ="1";
}else{
$addadd = "0";
}
if ($_POST["txtAddEdit"]=="on"){
$addedit ="1";
}else{
$addedit = "0";
}
if ($_POST["txtAddDelete"]=="on"){
$adddelete ="1";
}else{
$adddelete = "0";
}
if ($_POST["txtAddPrint"]=="on"){
$addprint ="1";
}else{
$addprint = "0";
}
//echo $addadd."66666"."<br>";
//echo $_POST["txtAddAdd"]."555555555";
$strSQL = "INSERT INTO group_detail ";
$strSQL .="(detail_id,group_id,menu_id,addcmd,editcmd,deletecmd,printcmd) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtAddDetail"]."','".$_POST["txtAddGroup"]."' ";
$strSQL .=",'".$_POST["txtAddMenu"]."','".$addadd."' ";
$strSQL .=",'".$addedit."','".$adddelete."' ";
$strSQL .=",'".$addprint."') ";
echo $strSQL;
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Save [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
/*echo $_POST["txtEditAdd"]."5555555555555555555555555<br>";
echo $_POST["txtEditEdit"]."5555555555555555555555555<br>";
echo $_POST["txtEditDelete"]."5555555555555555555555555<br>";
echo $_POST["txtEditPrint"]."5555555555555555555555555<br>";
*/
$strSQL = "UPDATE group_detail SET ";
$strSQL .="detail_id = '".$_POST["txtEditDetail"]."' ";
$strSQL .=",group_id = '".$_POST["txtEditGroup"]."' ";
$strSQL .=",menu_id = '".$_POST["txtEditMenu"]."' ";
$strSQL .=",addcmd = '".$_POST["txtEditAdd"]."' ";
$strSQL .=",editcmd = '".$_POST["txtEditEdit"]."' ";
$strSQL .=",deletecmd = '".$_POST["txtEditDelete"]."' ";
$strSQL .=",printcmd = '".$_POST["txtEditPrint"]."' ";
$strSQL .="WHERE detail_id = '".$_POST["hdnEditDetail"]."' ";
//echo $strSQL;
$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 group_detail,group_member ";
$strSQL .="WHERE detail_id = '".$_GET["CusID"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
//echo $_POST["member"];
$strSQL ="SELECT * FROM `group_detail` ,group_member where group_detail.group_id = group_member.group_id and group_member.group_id = '".$_POST["member"]."'";
//$strSQL = "select detail_id , group_detail.group_id , menu_id, addcmd , editcmd , deletecmd ,printcmd , a.group_name from group_detail,group_member a where a.group_id = group_detail.group_id and a.group_id = '".$_POST["member"]."'";
echo $strSQL;
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="<?=$_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<select name="member" id="member" onChange="this.form.submit()">
<option value=""><-- Please Select Item --></option>
<?
$q="select * from group_member";
$qr=mysql_query($q);
while($rs=mysql_fetch_array($qr)){
?>
<option value="<?=$rs['group_id']?>"><?=$rs['group_name']?></option>
<?} ?>
</select>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">Group Detail </div></th>
<th width="98"> <div align="center">Group ID </div></th>
<th width="198"> <div align="center">Menu ID </div></th>
<th width="97"> <div align="center">Add </div></th>
<th width="59"> <div align="center">Edit </div></th>
<th width="71"> <div align="center">Delete </div></th>
<th width="71"> <div align="center">print </div></th>
<th width="30"> <div align="center">Edit </div></th>
<th width="30"> <div align="center">Delete </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
$i++;
?>
<?
if($objResult["detail_id"] == $_GET["CusID"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td><div align="center">
<input type="text" name="txtEditDetail" size="5" value="<?=$objResult["detail_id"];?>">
<input type="hidden" name="hdnEditDetail" size="5" value="<?=$objResult["detail_id"];?>">
</div></td>
<td><input type="text" name="txtEditGroup" size="20" value="<?=$objResult["group_id"];?>"></td>
<td><input type="text" name="txtEditMenu" size="20" value="<?=$objResult["menu_id"];?>"></td>
<td><div align="center"><?//echo $objResult["addcmd"];
if($objResult["addcmd"] == 1){?>
<input type="checkbox" name ="txtEditAdd" value="1" checked="checked" />
<?}
else{
?>
<input type="checkbox" name ="txtEditAdd"value="1" />
<?}?></div></td>
<td><div align="center"><?//echo $objResult["editcmd"];
if($objResult["editcmd"] == 1){?>
<input type="checkbox" name ="txtEditEdit" value="1" checked="checked" />
<?}
else{
?>
<input type="checkbox" name = "txtEditEdit"value="1" />
<?}?></div></td>
<td><div align="center">
<? //echo $objResult["deletecmd"];
if($objResult["deletecmd"] == 1){?>
<input type="checkbox" name ="txtEditDelete" value="1" checked="checked" />
<?}
else{
?>
<input type="checkbox" name = "txtEditDelete"value="1" />
<?}?></div></td>
<td><div align="center">
<? //echo $objResult["printcmd"];
if($objResult["printcmd"] == 1){?>
<input type="checkbox" name ="txtEditPrint" value="1" checked="checked" />
<?}
else{
?>
<input type="checkbox" name ="txtEditPrint"value="1" />
<?}?></div></td>
<td colspan="2" align="right"><div align="center">
<input name="btnAdd" type="button" id="btnUpdate" value="Update" OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();">
<input name="btnAdd" type="button" id="btnCancel" value="Cancel" OnClick="window.location='<?=$_SERVER["PHP_SELF"];?>';">
</div></td>
</tr>
<?
}
else
{
?>
<tr>
<td><div align="center"><?=$objResult["detail_id"];?></div></td>
<td><div align="center"><?=$objResult["group_name"];?></div></td>
<td><div align="center"><?=$objResult["menu_id"];?></div></td>
<td><div align="center">
<?
//echo $objResult["addcmd"];
if($objResult["addcmd"] == 1){
?>
<input type="checkbox" value="1" checked="checked" />
<?}
else{
?>
<input type="checkbox" value="2" />
<?}
?></div></td>
<td><div align="center">
<?
//echo $objResult["editcmd"];
if($objResult["editcmd"] == 1){
?>
<input type="checkbox" value="1" checked="checked" />
<?}
else{
?>
<input type="checkbox" value="2" />
<?}
?></div></td>
<td><div align="center">
<?
//echo $objResult["deletecmd"];
if($objResult["deletecmd"] == 1){
?>
<input type="checkbox" value="1" checked="checked" />
<?}
else{
?>
<input type="checkbox" value="2" />
<?}
?></div></td>
<td><div align="center">
<?
//echo $objResult["printcmd"];
if($objResult["printcmd"] == 1){
?>
<input type="checkbox" value="1" checked="checked" />
<?}
else{
?>
<input type="checkbox" value="2" />
<?}
?></div></td>
<td align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&CusID=<?=$objResult["detail_id"];?>">Edit</a></td>
<td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&CusID=<?=$objResult["detail_id"];?>';}">Delete</a></td>
</tr>
<?
}
?>
<?
}
?>
<tr>
<td><div align="center"><input type="text" name="txtAddDetail" size="5"></div></td>
<td><input type="text" name="txtAddGroup" size="20"></td>
<td><input type="text" name="txtAddMenu" size="20"></td>
<td><div align="center"><input type="checkbox" name="txtAddAdd" size="2"></div></td>
<td align="center"><input type="checkbox" name="txtAddEdit" size="5"></td>
<td align="center"><input type="checkbox" name="txtAddDelete" size="5"></td>
<td align="center"><input type="checkbox" name="txtAddPrint" size="5"></td>
<td colspan="2" align="right"><div align="center">
<input name="btnAdd" type="button" id="btnAdd" value="Add" OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();">
</div></td>
</tr>
</table>
<input type="submit" name="btnsave" value="Save" onclick="javascript: form.action='phpMySQLAddMultiRecord.php';return onAdd();">
<input type="hidden" name="hdnCount" value="<?=$i;?>">
</form>
<?
mysql_close($objConnect);
?>
</body>
</html>
Date :
2011-01-26 11:31:39
By :
wanchat111
คือพอกด edit แล้ว ค่า $_POST["member"] บรรทัด 115 มันหายอ่ะครับ ค่า cusID มันมาแล้ว
Date :
2011-01-26 11:33:40
By :
wanchat111
Load balance : Server 00