|
|
|
ช่วยดูโค้ด phpmysql หน่อยครับ ว่าทำไมลบไม่ได้อะครับ |
|
|
|
|
|
|
|
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","07092536") or die("Error Connect to Database");
$objDB = mysql_select_db("dt_5222010003");
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
$strSQL = "INSERT INTO tb_5222010003 ";
$strSQL .="(id_card,name,address,email,tel) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtAddid_card"]."','".$_POST["txtAddname"]."' ";
$strSQL .=",'".$_POST["txtAddaddress"]."' ";
$strSQL .=",'".$_POST["txtAddemail"]."','".$_POST["txtAddtel"]."') ";
$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 tb_5222010003 SET ";
$strSQL .="id_card = '".$_POST["txtEditid_card"]."' ";
$strSQL .=",name = '".$_POST["txtEditname"]."' ";
$strSQL .=",address = '".$_POST["txtEditaddress"]."' ";
$strSQL .=",email = '".$_POST["txtEditemail"]."' ";
$strSQL .=",tel = '".$_POST["txtEdittel"]."' ";
$strSQL .="WHERE id_card = '".$_POST["hdnEditid_card"]."' ";
$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 tb_5222010003 ";
$strSQL .="WHERE id_card = '".$_GET["id"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
$strSQL = "SELECT * FROM tb_5222010003";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="<?=$_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">id_card</div></th>
<th width="98"> <div align="center">name </div></th>
<th width="198"> <div align="center">address </div></th>
<th width="198"> <div align="center">e-mail </div></th>
<th width="59"> <div align="center">tel </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))
{
?>
<?
if($objResult["id_card"] == $_GET["id_card"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td><div align="center">
<input type="text" name="txtEditid_card" size="5" value="<?=$objResult["id_card"];?>">
<input type="hidden" name="hdnEditid_card" size="5" value="<?=$objResult["id_card"];?>">
</div></td>
<td><input type="text" name="txtEditname" size="20" value="<?=$objResult["name"];?>"></td>
<td><input type="text" name="txtEditaddress" size="20" value="<?=$objResult["address"];?>"></td>
<td><div align="center"><input type="text" name="txtEditemail" size="2" value="<?=$objResult["email"];?>"></div></td>
<td align="right"><input type="text" name="txtEdittel" size="5" value="<?=$objResult["tel"];?>"></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["id_card"];?></div></td>
<td><?=$objResult["name"];?></td>
<td><?=$objResult["address"];?></td>
<td><div align="center"><?=$objResult["email"];?></div></td>
<td align="right"><?=$objResult["tel"];?></td>
<td align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&id_card=<?=$objResult["id_card"];?>">Edit</a></td>
<td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&id_card=<?=$objResult["id_card"];?>';}">Delete</a></td>
</tr>
<?
}
?>
<?
}
?>
<tr>
<td><div align="center"><input type="text" name="txtAddid_card" size="5"></div></td>
<td><input type="text" name="txtAddname" size="20"></td>
<td><input type="text" name="txtAddaddress" size="20"></td>
<td><div align="center"><input type="text" name="txtAddemail" size="2"></div></td>
<td align="right"><input type="text" name="txtAddemail" 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>
<?
mysql_close($objConnect);
?>
</body>
</html>
Tag : - - - -
|
|
|
|
|
|
Date :
2010-07-15 14:44:19 |
By :
งง |
View :
820 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$strSQL = "DELETE FROM tb_5222010003 ";
$strSQL .="WHERE id_card = '".$_GET["id"]."' ";
ลองใช้แบบนี้ดูนะครับ
$gid=$_GET['id'];
$srtSQL="delete from tb_5222010003 where id_card='$gid'";
|
|
|
|
|
Date :
2010-07-15 14:59:00 |
By :
boodemon |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|