ถามเรื่องbutton คือผมต้องการมีbuttonหลายปุ่มคือมีAdd,Edit,Delete,Cancelแล้วทีนี้พอตอนส่งค่าไปฟอร์มต่างๆเราจะเขียนยังไงดีละครับขอรบกวนผู้
<script language="JavaScript">
function Check(value)
{
document.all.frm.Command.value=value;
frm.submit();
}
</script>
<form name="frm" action="">
<input type="hiden" name="Command"> // เก็บคำสั่งใช้กำหนดเงื่อนไข
<input type="button" name="Save" Value="Save" OnClick="Check('Save')">
<input type="button" name="Del" Value="Del" OnClick="Check('Del')">
</form>
Date :
18 มิ.ย. 2550 17:44:41
By :
@W_IN
Code (PHP)
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
$strSQL = "INSERT INTO customer ";
$strSQL .="(CustomerID,Name,Email,CountryCode,Budget,Used) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtAddCustomerID"]."','".$_POST["txtAddName"]."' ";
$strSQL .=",'".$_POST["txtAddEmail"]."' ";
$strSQL .=",'".$_POST["txtAddCountryCode"]."','".$_POST["txtAddBudget"]."' ";
$strSQL .=",'".$_POST["txtAddUsed"]."') ";
$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 customer SET ";
$strSQL .="CustomerID = '".$_POST["txtEditCustomerID"]."' ";
$strSQL .=",Name = '".$_POST["txtEditName"]."' ";
$strSQL .=",Email = '".$_POST["txtEditEmail"]."' ";
$strSQL .=",CountryCode = '".$_POST["txtEditCountryCode"]."' ";
$strSQL .=",Budget = '".$_POST["txtEditBudget"]."' ";
$strSQL .=",Used = '".$_POST["txtEditUsed"]."' ";
$strSQL .="WHERE CustomerID = '".$_POST["hdnEditCustomerID"]."' ";
$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 customer ";
$strSQL .="WHERE CustomerID = '".$_GET["CusID"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
Go to : PHP MySQL Add/Insert/Edit/Delete to MySQL On Same Form
Date :
2011-06-13 22:02:17
By :
webmaster
Load balance : Server 02