|
|
|
กด delete แล้วมันไม่ลบให้ ดูให้หน่อยครับว่าโค้ดมันผิดตรงไหน |
|
|
|
|
|
|
|
ช่วยดูให้ทีครับช่วง Delete มีตรงไหนผิด ทำไมกดลบแล้วมันไม่ลบ
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?php
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("memberdb");
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
$strSQL = "INSERT INTO member ";
$strSQL .="(BookID,BookName,TName,PName,Year,Dep) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtAddBookID"]."','".$_POST["txtAddBookName"]."' ";
$strSQL .=",'".$_POST["txtAddTName"]."' ";
$strSQL .=",'".$_POST["txtAddPName"]."','".$_POST["txtAddYear"]."' ";
$strSQL .=",'".$_POST["txtAddDep"]."') ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Save [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
$strSQL = "UPDATE member SET ";
$strSQL .="BookID = '".$_POST["txtEditBookID"]."' ";
$strSQL .=",BookName = '".$_POST["txtEditBookName"]."' ";
$strSQL .=",TName = '".$_POST["txtEditTName"]."' ";
$strSQL .=",PName = '".$_POST["txtEditPName"]."' ";
$strSQL .=",Year = '".$_POST["txtEditYear"]."' ";
$strSQL .=",Dep = '".$_POST["txtEditDep"]."' ";
$strSQL .="WHERE BookID = '".$_POST["hdnEditBookID"]."' ";
$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 member ";
$strSQL .="WHERE BookID = '".$_GET["CusID"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
$strSQL = "SELECT * FROM member";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">BookID </div></th>
<th width="98"> <div align="center">BookName </div></th>
<th width="198"> <div align="center">TName </div></th>
<th width="97"> <div align="center">PName </div></th>
<th width="59"> <div align="center">Year </div></th>
<th width="71"> <div align="center">Dep </div></th>
<th width="30"> <div align="center">Edit </div></th>
<th width="30"> <div align="center">Delete </div></th>
</tr>
<?php
while($objResult = mysql_fetch_array($objQuery))
{
?>
<?php
if($objResult["BookID"] == $_GET["CusID"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td><div align="center">
<input type="text" name="txtEditBookID" size="5" value="<?php echo $objResult["BookID"];?>">
<input type="hidden" name="hdnEditBookID" size="5" value="<?php echo $objResult["BookID"];?>">
</div></td>
<td><input type="text" name="txtEditBookName" size="20" value="<?php echo $objResult["BookName"];?>"></td>
<td><input type="text" name="txtEditTName" size="20" value="<?php echo $objResult["TName"];?>"></td>
<td><div align="center"><input type="text" name="txtEditPName" size="2" value="<?php echo $objResult["PName"];?>"></div></td>
<td align="right"><input type="text" name="txtEditYear" size="5" value="<?php echo $objResult["Year"];?>"></td>
<td align="right"><input type="text" name="txtEditDep" size="5" value="<?php echo $objResult["Dep"];?>"></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='<?php echo $_SERVER["PHP_SELF"];?>';">
</div></td>
</tr>
<?php
}
else
{
?>
<tr>
<td><div align="center"><?php echo $objResult["BookID"];?></div></td>
<td><?php echo $objResult["BookName"];?></td>
<td><?php echo $objResult["TName"];?></td>
<td><div align="center"><?php echo $objResult["PName"];?></div></td>
<td align="right"><?php echo $objResult["Year"];?></td>
<td align="right"><?php echo $objResult["Dep"];?></td>
<td align="center"><a href="<?php echo $_SERVER["PHP_SELF"];?>?Action=Edit&CusID=<?php echo $objResult["BookID"];?>">Edit</a></td>
<td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?php echo $_SERVER["PHP_SELF"];?>?Action=Del&CusID=<?php echo $objResult["BookID"];?>';}">Delete</a></td>
</tr>
<?php
}
?>
<?php
}
?>
<tr>
<td><div align="center"><input type="text" name="txtAddBookID" size="5"></div></td>
<td><input type="text" name="txtAddBookName" size="20"></td>
<td><input type="text" name="txtAddTName" size="20"></td>
<td><div align="center"><input type="text" name="txtAddPName" size="2"></div></td>
<td align="right"><input type="text" name="txtAddYear" size="5"></td>
<td align="right"><input type="text" name="txtAddDep" 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>
</form>
<?php
mysql_close($objConnect);
?>
</body>
</html>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2015-04-01 17:18:26 |
By :
peemmer |
View :
631 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ดูแล้วโค้ดไม่มีที่ผิดเลยครับ
|
|
|
|
|
Date :
2015-04-01 20:09:21 |
By :
ไม่ทราบแหล่งที่มา |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.....
|
ประวัติการแก้ไข 2015-04-01 21:22:00
|
|
|
|
Date :
2015-04-01 21:17:36 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กด ลบไม่ออก TT
|
|
|
|
|
Date :
2015-04-01 22:50:22 |
By :
peemmer |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อ่านโค๊ดแล้วไม่น่าผิดอะไรนะครับ
ก็ลองดู error message ดูหน่อย
และรายงานผลการคิวรี่
เพิ่มส่วนสีน้ำตาลครับ เพื่อทดสอบคำสั่ง
054.$objQuery = mysql_query($strSQL) or die ( mysql_error() . "<br>[[ $strSQL ]]");
echo "จำนวน record ที่ลบได้ " . mysql_affected_rows();
055.if(!$objQuery)
|
|
|
|
|
Date :
2015-04-02 05:09:20 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|