Monday, April 29, 2013

Delete data from list and instant postback from another page

Create a file named aclist.php, which will contain account list and a delete image.

<?php
session_start();
if(!$_session=$myusername){
header("location:index.php");
}
?>
<head>
<title>WELCOME CUSTOMER</title>
</head>
<body>
<h2><center>Account List</center></h2>
<br>
<?php
error_reporting(E_ALL ^ E_NOTICE);

$username = 'DBUSER';
$password = 'DBPASS';
$ora_host='(DESCRIPTION =(ADDRESS =(PROTOCOL = TCP)(HOST = 102.101.2.1)(PORT = 1521))(CONNECT_DATA =(SID = DBNAME)))';
$objConnect = ocilogon($username, $password, $ora_host);

$strSQL = "select *from TABLENAME";
$objParse = oci_parse ($objConnect, $strSQL);
oci_execute ($objParse,OCI_DEFAULT);
$Num_Rows = oci_fetch_all($objParse, $Result);
$strSQLa = "SELECT AC.ACCOUNTNUMBER, AC.NAME ACN, ba.name BCN, cat.name CCN, st.name DCN, pac.MSG ECN FROM TABLE_NAME where pac.ACCOUNTNUMBER = AC.ACCOUNTNUMBER";

$objParsea = oci_parse ($objConnect, $strSQLa);
oci_execute ($objParsea,OCI_DEFAULT);
$Num_Rows2 = oci_fetch_all($objParsea, $Resulta);

$Per_Page = 7;   // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$Page_End = $Per_Page * $Page;
if ($Page_End > $Num_Rows)
{
$Page_End = $Num_Rows;
}

print "<center>";
print "<table border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"1\" >";
print "<tr border=\"1\">";
print "<td valign=\"top\" style=\"border:1px solid black\" width=\"150\"><p align=\"center\"><b>ACCOUNT NUMBER</td>";
print "<td valign=\"top\" style=\"border:1px solid black\" width=\"300\"><p align=\"center\"><b>NAME</td>";
print "<td valign=\"top\" style=\"border:1px solid black\" width=\"150\"><p align=\"center\"><b>AREA</td>";
print "<td valign=\"top\" style=\"border:1px solid black\" width=\"80\"><p align=\"center\"><b>CATEGORY</td>";
print "<td valign=\"top\" style=\"border:1px solid black\" width=\"80\"><p align=\"center\"><b>STATUS</td>";
print "<td valign=\"top\" style=\"border:1px solid black\" width=\"80\"><p align=\"center\"><b>MSG</td>";
print "</tr>";

for($i=$Page_Start;$i<$Page_End;$i++)
{
?>

<tr border=\"1\">
<td valign="top" style="border:1px solid black"><font color="black"><?php print $Result["ACCOUNTNUMBER"][$i];?></td>
<td valign="top" style="border:1px solid black"><font color="black"><?php print $Resulta["ACN"][$i];?></td>
<td valign="top" style="border:1px solid black"><font color="black"><?php print $Resulta["BCN"][$i];?></td>
<td valign="top" style="border:1px solid black"><font color="black"><?php print $Resulta["CCN"][$i];?></td>
<td valign="top" style="border:1px solid black"><font color="black"><?php print $Resulta["DCN"][$i];?></td>
<td valign="top" style="border:1px solid black"><font color="black"><?php print $Resulta["ECN"][$i];?></td>
<?php
$ac_num=$Result["ACCOUNTNUMBER"][$i];
print "<td width=\"30\"><form action=\"delcsms.php\" method=\"POST\">";
print "<input type=\"hidden\" name=\"ac_no\" value=\"$ac_num\">";
print "<input type=\"image\" id=\"enter\"  name=\"submit: width=\"30\" height=\"15\" src=\"del.png\">";
?>
</tr>
</form>
<?
}
?>
</table>
</center>
<br>
<center><table align="center" style="width:50%; ">
<font size=2><b>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}

for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
}
oci_close($objConnect);
//}
?>
</p>
<?php
}
else
{
print "<img src=\"access_denied.gif\" alt=\"ACCESS\" width=\"255\" height=\"77\" />";
}
?>
</table></center>
</b></font>
</center>
</body>
</html>
Create another page delcsms.php  where delete query will run and redirect to aclist.php page. Just include these code to delcsms.php page.

<?php
$acc_no=$_POST['ac_no'];
print "<br>ACC_NO".$acc_no;
error_reporting(E_ALL ^ E_NOTICE);
if($acc_no)
{
$username = 'DBUSER';
$password = 'DBPASS';
$ora_host='(DESCRIPTION =(ADDRESS =(PROTOCOL = TCP)(HOST = 121.123.0.1)(PORT = 1521))(CONNECT_DATA =(SID =DBNAME)))';
$objConnect = ocilogon($username, $password, $ora_host);
$strSQL = "delete from TABLE_NAME where ACCOUNTNUMBER = '$acc_no'";
$objParse = oci_parse ($objConnect, $strSQL);
oci_execute ($objParse,OCI_DEFAULT);
oci_commit($objConnect);
oci_close($objConnect);
header("location:aclistc.php");
}
?>

No comments:

Post a Comment