web 2.0

How to use PHP & Oracle (oci8) Edit/Update Multiple Rows Record

How to use PHP & Oracle (oci8) Edit/Update Multiple Rows Record This is the guideline/example scripts how to use PHP edit/update multiple record on Oracle database.

ShotDev Focus:
- PHP & Oracle edit/update multiple record.

Example

php_oracle_multiple_update.php


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

//*** Update Condition ***//
if($_GET["Action"] == "Save")
{
for($i=1;$i<=$_POST["hdnLine"];$i++)
{
$strSQL = "UPDATE customer SET ";
$strSQL .="CustomerID = '".$_POST["txtCustomerID$i"]."' ";
$strSQL .=",Name = '".$_POST["txtName$i"]."' ";
$strSQL .=",Email = '".$_POST["txtEmail$i"]."' ";
$strSQL .=",CountryCode = '".$_POST["txtCountryCode$i"]."' ";
$strSQL .=",Budget = '".$_POST["txtBudget$i"]."' ";
$strSQL .=",Used = '".$_POST["txtUsed$i"]."' ";
$strSQL .="WHERE CustomerID = '".$_POST["hdnCustomerID$i"]."' ";
$objParse = oci_parse($objConnect, $strSQL);
$objExecute = oci_execute($objParse,OCI_DEFAULT);
oci_commit($objConnect);
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}

$strSQL = "SELECT * FROM CUSTOMER ORDER BY CUSTOMERID ASC";
$objParse = oci_parse($objConnect, $strSQL);
oci_execute ($objParse,OCI_DEFAULT);
?>
<form name="frmMain" method="post" action="php_oracle_multiple_update.php?Action=Save">
<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>
</tr>
<?
$i =0;
while($objResult = oci_fetch_array($objParse,OCI_BOTH))
{
$i = $i + 1;
?>
<tr>
<td><div align="center">
<input type="hidden" name="hdnCustomerID<?=$i;?>" size="5" value="<?=$objResult["CUSTOMERID"];?>">
<input type="text" name="txtCustomerID<?=$i;?>" size="5" value="<?=$objResult["CUSTOMERID"];?>">
</div></td>
<td><input type="text" name="txtName<?=$i;?>" size="20" value="<?=$objResult["NAME"];?>"></td>
<td><input type="text" name="txtEmail<?=$i;?>" size="20" value="<?=$objResult["EMAIL"];?>"></td>
<td><div align="center"><input type="text" name="txtCountryCode<?=$i;?>" size="2" value="<?=$objResult["COUNTRYCODE"];?>"></div></td>
<td align="right"><input type="text" name="txtBudget<?=$i;?>" size="5" value="<?=$objResult["BUDGET"];?>"></td>
<td align="right"><input type="text" name="txtUsed<?=$i;?>" size="5" value="<?=$objResult["USED"];?>"></td>
</tr>
<?
}
?>
</table>
<input type="submit" name="submit" value="submit">
<input type="hidden" name="hdnLine" value="<?=$i;?>">
</form>
<?
oci_close($objConnect);
?>
</body>
</html>

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

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

Screenshot

PHP & Oracle (oci8) Edit/Update Multiple Record

.
.
.
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.