|
|
|
PHP MySQL Add/Insert/Edit/Delete to MySQL On Same Form UPDATE ไม่ได้ค่ะ |
|
|
|
|
|
|
|
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
include"connect.php";
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
$prdate = date("Y-m-d");
$prtime = date("H:i:s");
$strSQL = "INSERT INTO purchase ";
$strSQL .="(idno,prno,brand,class,qtymotor,emp_no,prdate,prtime)";
$strSQL .="VALUES ";
$strSQL .="('$idno','$prno' ,'".$_POST["brand"]."','".$_POST["class"]."','".$_POST["qtymotor"]."','".$_POST["emp_no"]."','$prdate','$prtime') ";
$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 purchase SET ";
$strSQL .="idno = '".$_GET["txtEditidno"]."' ";
$strSQL .=",brand = '".$_POST["txtEditbrand"]."' ";
$strSQL .=",class = '".$_POST["txtEditclass"]."' ";
$strSQL .=",qtymotor = '".$_POST["txtEditqtymotor"]."' ";
$strSQL .="WHERE idno = '".$_GET["hdnEditidno"]."' ";
$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 purchase ";
$strSQL .="WHERE idno = '".$_GET["idno"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
$strSQL = "SELECT * FROM purchase";
$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"># </div></th>
<th width="91"> <div align="center">ยี่ห้อ </div></th>
<th width="98"> <div align="center">รุ่น </div></th>
<th width="198"> <div align="center">จำนวน </div></th>
<th width="30"> <div align="center">แก้ไข </div></th>
<th width="30"> <div align="center">ลบ </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<?
if($objResult["idno"] == $_GET["idno"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td>
<input type="text" name="txtEditidno" size="5" value="<?=$objResult["idno"];?>">
<input type="hidden" name="hdnEditidno" size="5" value="<?=$objResult["idno"];?>">
</td>
<td><div align="center">
<input type="text" name="txtEditbrand" size="5" value="<?=$objResult["brand"];?>">
</td>
<td><input type="text" name="txtEditclass" size="20" value="<?=$objResult["class"];?>"></td>
<td><input type="text" name="txtEditqtymotor" size="20" value="<?=$objResult["qtymotor"];?>"></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["idno"];?></div></td>
<td><div align="center"><?=$objResult["brand"];?></div></td>
<td><?=$objResult["class"];?></td>
<td><?=$objResult["qtymotor"];?></td>
<td align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&idno=<?=$objResult["idno"];?>">แก้ไข</a></td>
<td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&idno=<?=$objResult["idno"];?>';}">ลบ</a></td>
</tr>
<?
}
?>
<?
}
?>
<tr>
<td><div align="center"><input type="text" name="idno" size="5"></div></td>
<td><div align="center"><input type="text" name="brand" size="5"></div></td>
<td><input type="text" name="class" size="20"></td>
<td><input type="text" name="qtymotor" size="20"></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 : PHP
|
|
|
|
|
|
Date :
2013-10-22 13:52:01 |
By :
PALM26 |
View :
2413 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|