web 2.0

How to use PHP & Oracle (oci8) Delete Multiple Rows Record Using Checkbox

How to use PHP & Oracle (oci8) Delete Multiple Rows Record Using Checkbox This is the guideline/example scripts how to use PHP delete multiple record from Oracle database.

ShotDev Focus:
- PHP & Oracle database delete multiple record using checkbox.

Example 1

php_oracle_checkbox1.php


<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<script language="JavaScript">
function onDelete()
{
if(confirm('Do you want to delete ?')==true)
{
return true;
}
else
{
return false;
}
}
</script>
<form name="frmMain" action="php_oracle_checkbox2.php" method="post" OnSubmit="return onDelete();">
<?
$objConnect = oci_connect("myuser","mypassword","TCDB");
$strSQL = "SELECT * FROM CUSTOMER";
$objParse = oci_parse ($objConnect, $strSQL);
oci_execute ($objParse,OCI_DEFAULT);
?>
<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">Delete </div></th>
</tr>
<?
while($objResult = oci_fetch_array($objParse,OCI_BOTH))
{
?>
<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"><input type="checkbox" name="chkDel[]" value="<?=$objResult["CUSTOMERID"];?>"></td>
</tr>
<?
}
?>
</table>
<?
oci_close($objConnect);
?>
<input type="submit" name="btnDelete" value="Delete">
</form>
</body>
</html>

php_oracle_checkbox2.php


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

for($i=0;$i<count($_POST["chkDel"]);$i++)
{
if($_POST["chkDel"][$i] != "")
{
$strSQL = "DELETE FROM CUSTOMER ";
$strSQL .="WHERE CUSTOMERID = '".$_POST["chkDel"][$i]."' ";
$objParse = oci_parse($objConnect, $strSQL);
$objExecute = oci_execute($objParse, OCI_DEFAULT);
}
}

oci_commit($objConnect); //*** Commit Transaction ***//
echo "Record Deleted.";

oci_close($objConnect);
?>
</body>
</html>

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

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

Screenshot

PHP & Oracle (oci8) Delete Multiple Record Using Checkbox
.
.

Example 2 (Check All Button)

php_oracle_checkbox3.php


<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<script language="JavaScript">
function ClickCheckAll(vol)
{
var i=1;
for(i=1;i<=document.frmMain.hdnCount.value;i++)
{
if(vol.checked == true)
{
eval("document.frmMain.chkDel"+i+".checked=true");
}
else
{
eval("document.frmMain.chkDel"+i+".checked=false");
}
}
}

function onDelete()
{
if(confirm('Do you want to delete ?')==true)
{
return true;
}
else
{
return false;
}
}
</script>
<form name="frmMain" action="php_oracle_checkbox2.php" method="post" OnSubmit="return onDelete();">
<?
$objConnect = oci_connect("myuser","mypassword","TCDB");
$strSQL = "SELECT * FROM CUSTOMER";
$objParse = oci_parse ($objConnect, $strSQL);
oci_execute ($objParse,OCI_DEFAULT);
?>
<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">
<input name="CheckAll" type="checkbox" id="CheckAll" value="Y" onClick="ClickCheckAll(this);">
</div></th>
</tr>
<?
$i = 0;
while($objResult = oci_fetch_array($objParse,OCI_BOTH))
{
$i++;
?>
<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"><input type="checkbox" name="chkDel[]" id="chkDel<?=$i;?>" value="<?=$objResult["CUSTOMERID"];?>"></td>
</tr>
<?
}
?>
</table>
<?
oci_close($objConnect);
?>
<input type="submit" name="btnDelete" value="Delete">
<input type="hidden" name="hdnCount" value="<?=$i;?>">
</form>
</body>
</html>

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

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

Screenshot

PHP & Oracle (oci8) Delete Multiple Record Using Checkbox
.
.
.
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.