web 2.0

How to use PHP & Oracle (oci8) Add/Insert/Edit/Delete On Same Form

How to use PHP & Oracle (oci8) Add/Insert/Edit/Delete On Same Form This is the guideline/example scripts how to use PHP delete multiple record from Oracle database.

ShotDev Focus:
- PHP & Oracle database add/insert/update/delete on same form.

Example 1

php_oracle_command.php


<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?
$objConnect = oci_connect("myuser","mypassword","TCDB");

//*** 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"]."') ";
$objParse = oci_parse($objConnect, $strSQL);
$objExecute = oci_execute($objParse, OCI_DEFAULT);
if($objExecute)
{
oci_commit($objConnect);
}
else
{
$e = oci_error($objParse);
echo "Error Add [".$e['message']."]";
}
//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"]."' ";
$objParse = oci_parse($objConnect, $strSQL);
$objExecute = oci_execute($objParse, OCI_DEFAULT);
if($objExecute)
{
oci_commit($objConnect);
}
else
{
$e = oci_error($objParse);
echo "Error Update [".$e['message']."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}

//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
$strSQL = "DELETE FROM CUSTOMER ";
$strSQL .="WHERE CUSTOMERID = '".$_GET["CusID"]."' ";
$objParse = oci_parse($objConnect, $strSQL);
$objExecute = oci_execute($objParse, OCI_DEFAULT);
if($objExecute)
{
oci_commit($objConnect);
}
else
{
$e = oci_error($objParse);
echo "Error Delete [".$e['message']."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}

$objConnect = oci_connect("myuser","mypassword","TCDB");
$strSQL = "SELECT * FROM CUSTOMER ORDER BY CUSTOMERID ASC";
$objParse = oci_parse($objConnect, $strSQL);
oci_execute ($objParse,OCI_DEFAULT);
?>
<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">CUSTOMERID </div></th>
<th width="98"> <div align="center">NAME </div></th>
<th width="198"> <div align="center">EMAIL </div></th>
<th width="97"> <div align="center">COUNTRYCODE </div></th>
<th width="59"> <div align="center">BUDGET </div></th>
<th width="71"> <div align="center">USED </div></th>
<th width="30"> <div align="center">Edit </div></th>
<th width="30"> <div align="center">Delete </div></th>
</tr>
<?
while($objResult = oci_fetch_array($objParse,OCI_BOTH))
{
?>

<?
if($objResult["CUSTOMERID"] == $_GET["CusID"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td><div align="center">
<input type="text" name="txtEditCustomerID" size="5" value="<?=$objResult["CUSTOMERID"];?>">
<input type="hidden" name="hdnEditCustomerID" size="5" value="<?=$objResult["CUSTOMERID"];?>">
</div></td>
<td><input type="text" name="txtEditName" size="20" value="<?=$objResult["NAME"];?>"></td>
<td><input type="text" name="txtEditEmail" size="20" value="<?=$objResult["EMAIL"];?>"></td>
<td><div align="center"><input type="text" name="txtEditCountryCode" size="2" value="<?=$objResult["COUNTRYCODE"];?>"></div></td>
<td align="right"><input type="text" name="txtEditBudget" size="5" value="<?=$objResult["BUDGET"];?>"></td>
<td align="right"><input type="text" name="txtEditUsed" size="5" value="<?=$objResult["USED"];?>"></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["CUSTOMERID"];?></div></td>
<td><?=$objResult["NAME"];?></td>
<td><?=$objResult["EMAIL"];?></td>
<td><div align="center"><?=$objResult["COUNTRYCODE"];?></div></td>
<td align="right"><?=$objResult["BUDGET"];?></td>
<td align="right"><?=$objResult["USED"];?></td>
<td align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&CusID=<?=$objResult["CUSTOMERID"];?>">Edit</a></td>
<td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&CusID=<?=$objResult["CUSTOMERID"];?>';}">Delete</a></td>
</tr>
<?
}
?>
<?
}
?>
<tr>
<td><div align="center"><input type="text" name="txtAddCustomerID" size="5"></div></td>
<td><input type="text" name="txtAddName" size="20"></td>
<td><input type="text" name="txtAddEmail" size="20"></td>
<td><div align="center"><input type="text" name="txtAddCountryCode" size="2"></div></td>
<td align="right"><input type="text" name="txtAddBudget" size="5"></td>
<td align="right"><input type="text" name="txtAddUsed" 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>
<?
oci_close($objConnect);
?>
</body>
</html>

Create a php file and save to path root-path/myphp/

Run
http://localhost/myphp/php_oracle_command.php

Screenshot

PHP & Oracle (oci8) Add/Insert/Edit/Delete On Same Form

.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.