Hello,
Could somebody please help me in combining my two scripts.Both work pretty fine.The first script is used to update all my fields and the second is script is used to delete the fields in a table by using check boxes.
Now, i want to implement these two in one, i.e i can either update or delete them.Please help me in combining the both.
//Update.php
<?php
include "dbconnection.ini";
if ($HTTP_POST_VARS)
{
$cnt = count($HTTP_POST_VARS['id']);
for($cntr=0;$cntr<$cnt;$cntr++)
{
if (!$HTTP_POST_VARS['enrolment'][$cntr]) $enrolment=0; else $enrolment=1;
if (!$HTTP_POST_VARS['ciphering'][$cntr]) $ciphering=0; else $ciphering=1;
$update_sql = "update TBL_RBS SET ".
"RBS_RFPI = '{$HTTP_POST_VARS['rfpi'][$cntr]}', ".
"RBS_IPADDRESS = '{$HTTP_POST_VARS['ip_address'][$cntr]}', ".
"RBS_ENROLMENT = $enrolment, ".
"RBS_CIPHERING = $ciphering, ".
"RBS_MACADDRESS = '{$HTTP_POST_VARS['mac_address'][$cntr]}', ".
"RBS_SUBNETMASK = '{$HTTP_POST_VARS['subnet_mask'][$cntr]}', ".
"RBS_ROUTERIP = '{$HTTP_POST_VARS['router_ip'][$cntr]}', ".
"RBS_TFTPSERVERIPADDRESS = '{$HTTP_POST_VARS['tftp_server'][$cntr]}', ".
"RBS_TFTPFILENAME = '{$HTTP_POST_VARS['tftp_file'][$cntr]}' ".
"where RBS_ID = {$HTTP_POST_VARS['id'][$cntr]}";
$update_results = ibase_query($update_sql);
if (!$update_results) {
echo "Error executing the update statement. <br />Interbase Reported:".ibase_errmsg()." <br/>".
"SQL=$update_sql<br />\n";
}
}
}
$select_sql = 'Select RBS_ID, RBS_TFTPSERVERIPADDRESS, '.
'RBS_TFTPFILENAME, RBS_ENROLMENT, RBS_CIPHERING, '.
'RBS_RFPI, RBS_IPADDRESS, RBS_MACADDRESS, RBS_SUBNETMASK, '.
'RBS_ROUTERIP from TBL_RBS';
$result_id = ibase_query($select_sql) or die('Error retrieving records from TBL_RBS.<br />Interbase Reported: '.ibase_errmsg());
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../formate.css">
</head>
<p style="line-height:100%; margin-top:0; margin-bottom:0;"><h1>
<tr style="margin:0; padding:0;">
<?php
$counter=0;
$old_values=null;
while ($row = ibase_fetch_object($result_id)) {
$rfpi=$row->RBS_RFPI;
$ciphering=$row->RBS_CIPHERING;
$ipaddress=$row->RBS_IPADDRESS;
$macaddress=$row->RBS_MACADDRESS;
$subnetmask=$row->RBS_SUBNETMASK;
$routerip=$row->RBS_ROUTERIP;
$enrolment=$row->RBS_ENROLMENT;
$tftpserver=$row->RBS_TFTPSERVERIPADDRESS;
$tftpfile=$row->RBS_TFTPFILENAME;
?>
<td width="78" height="23" align="left" valign="top">
<p style="line-height:100%; margin-top:0; margin-bottom:0;"><FONT face=Verdana>
<SPAN style="FONT-SIZE: 10pt">
<INPUT type="text" size="10" name="rfpi[<?=$counter?>]" value="<?=$rfpi?>"style="padding:0;">
</SPAN></FONT></p></td>
<td width="78" height="23" align="left" valign="top">
<P style="line-height:100%; margin-top:0; margin-bottom:0;"><font face="Verdana">
<span style="font-size:10pt;">
<input type="text" size="10" name="ip_address[<?=$counter?>]" value="<?=$ipaddress?>">
</span></font></P></td>
<td width="75" height="23" align="left" valign="top">
<P style="line-height:100%; margin-top:0; margin-bottom:0;"><FONT face=Verdana>
<SPAN style="FONT-SIZE: 10pt">
<INPUT type=checkbox name="enrolment[<?=$counter?>]" value="1"<? if ($enrolment==1)echo "checked";?>>
</SPAN></FONT></P></td>
<td width="75" height="23" align="left" valign="top">
<P style="line-height:100%; margin-top:0; margin-bottom:0;"><FONT face=Verdana>
<SPAN style="FONT-SIZE: 10pt">
<INPUT type=checkbox name="ciphering[<?=$counter?>]" value="1" <? if ($ciphering==1)echo "checked";?>>
</SPAN></FONT></P></td>
<td width="85" height="23" align="left" valign="top">
<P style="line-height:100%; margin-top:0; margin-bottom:0;"><FONT face=Verdana>
<SPAN style="FONT-SIZE: 10pt">
<INPUT type="text" size="10" name="mac_address[<?=$counter?>]" value="<?=$macaddress?>">
</SPAN></FONT></P></td>
<td width="78" height="23" align="left" valign="top">
<P style="line-height:100%; margin-top:0; margin-bottom:0;"><font face="Verdana">
<span style="font-size:10pt;">
<input type="text" size="10" name="subnet_mask[<?=$counter?>]" value="<?=$subnetmask?>">
</span></font></P></td>
<td width="84" height="23" align="left" valign="top">
<p style="line-height:100%; margin-top:0; margin-bottom:0;"><font face="Verdana">
<span style="font-size:10pt;">
<input type="text" size="10" name="router_ip[<?=$counter?>]" value="<?=$routerip?>">
</span></font></p></td>
<td width="84" height="23" align="left" valign="top">
<p style="line-height:100%; margin-top:0; margin-bottom:0;"><font face="Verdana">
<span style="font-size:10pt;">
<input type="text" size="10" name="tftp_server[<?=$counter?>]" value="<?=$tftpserver?>">
</span></font></p></td>
<td width="106" height="23" align="left" valign="top">
<p style="line-height:100%; margin-top:0; margin-bottom:0;"><font face="Verdana">
<span style="font-size:10pt;">
<input type="text" size="15" name="tftp_file[<?=$counter?>]" value="<?=$tftpfile?>">
</span></font></p></td>
<td width="55" height="23" align="left" valign="top" bgcolor="#dddddd">
<P style="line-height:100%; margin-top:0; margin-bottom:0;"><FONT face=Verdana>
<SPAN style="FONT-SIZE: 10pt">
<INPUT type=checkbox name="delete[<?=$counter?>]" value="1">
</SPAN></FONT></P></td>
</tr>
<?php
$old_values.=' <input type="hidden" name="id['.$counter.']" value="'.$row->RBS_ID.'">
';
$counter++;
}
?>
</table>
<?=$old_values?>
<Input type="image" src="../images/sign_save.gif" name="submit" value="Update" buttononclick="document.all.super_img.style.display = 'block'">
<Input type="image" src="../images/sign_cleanup.gif" name="submit" value="Update" style="dispay:none" id="super-img">
<input type="hidden" value="Reset">
</form>
</body>
</html>
//Delete.php
<?php
include "dbconnection.ini";
if (isset($HTTP_POST_VARS["delete"])) {
// the first "submit"
if (isset($HTTP_POST_VARS["submit"]))
{
$delete = $HTTP_POST_VARS["delete"];
if (is_array($delete) && !empty($delete))
{
reset($delete);
while (list($key,$id) = each($delete))
{
$sql = "UPDATE TBL_RBS SET RBS_DELETE = 1 where RBS_ID = $id";
$result = ibase_query($sql);
if (!$result) {
/* the query failed*/
echo "Error executing the update statement. <br />Interbase Reported:".ibase_errmsg()." <br/>".
"SQL=$sql<br />\n";
}
}
$delete_serialized = urlencode(serialize($delete));
echo "
<center>
<B>Chosen records marked for removal! </B><BR>\n
<B>Do you really want to remove them? </B><BR>\n
<form name=\"formConfirm\" method=\"post\" action=\"\">
<input type=\"hidden\" name=\"delete\" value=\"$delete_serialized\">
<input type=\"submit\" name=\"confirmed\" value=\"Yes!\">
<input type=\"submit\" name=\"cancel\" value=\"No!\"><BR>\n
</form>
</center>
";
exit;
}
}
// the second form submit (confirmed)
else if (isset($HTTP_POST_VARS["confirmed"]))
{
$delete = $HTTP_POST_VARS["delete"];
$delete = unserialize(urldecode($delete));
reset($delete);
if (is_array($delete) && !empty($delete))
{
reset($delete);
while (list($key,$id) = each($delete))
{
$sql = "DELETE from TBL_RBS where RBS_ID = $id";
$result = ibase_query($sql);
}
}
}
// the second form submit (cancel)
else if (isset($HTTP_POST_VARS["cancel"]))
{
$delete = $HTTP_POST_VARS["delete"];
$delete = unserialize(urldecode($delete));
reset($delete);
if (is_array($delete) && !empty($delete))
{
reset($delete);
while (list($key,$id) = each($delete))
{
$sql = "update TBL_RBS SET RBS_DELETE = 0 where RBS_ID = $id";
$result = ibase_query($sql);
}
}
}
}
//Select statement is here
?>
<b>To delete records</b></p>
<form name="editRBS" action="<?=$HTTP_SERVER_VARS['PHP_SELF']?>" method="POST">
<table cellpadding="0" cellspacing="0" width="909">
<?php
while ($row = ibase_fetch_object($result_id)) {
$rfpi=$row->RBS_RFPI;
$ciphering=$row->RBS_CIPHERING;
$ipaddress=$row->RBS_IPADDRESS;
$macaddress=$row->RBS_MACADDRESS;
$subnetmask=$row->RBS_SUBNETMASK;
$routerip=$row->RBS_ROUTERIP;
$enrolment=$row->RBS_ENROLMENT;
$tftpserver=$row->RBS_TFTPSERVERIPADDRESS;
$tftpfile=$row->RBS_TFTPFILENAME;
?>
<tr style="margin:0; padding:0;" align="left" valign="top">
<td width="156" height="23">
<input type="text" name="rfpi" value="<?=$rfpi?>">
</td>
<td width="154" height="23">
<input type="text" name="ip_address" value="<?=$ipaddress?>">
</td>
<td width="69" height="23">
<input type="checkbox" name="enrolment" value="1"<? if ($enrolment==1)echo "checked";?>>
</td>
<td width="65" height="23">
<input type="checkbox" name="ciphering" value="1" <? if ($ciphering==1)echo "checked";?>>
</td>
<td width="155" height="23">
<input type="text" name="mac_address" value="<?=$macaddress?>">
</td>
<td width="156" height="23">
<input type="text" name="subnet_mask" value="<?=$subnetmask?>">
</td>
<td width="156" height="23">
<input type="text" name="router_ip" value="<?=$routerip?>">
</td>
<td width="156" height="23">
<input type="text" name="tftp_server" value="<?=$tftpserver?>">
</td>
<td width="156" height="23">
<input type="text" name="tftp_file" value="<?=$tftpfile?>">
</td>
<td width="69" height="23">
<input type="checkbox" name="delete[]" value="<?=$row->RBS_ID?>">
</td>
</tr>
<?
}
?>
</table>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>