chinni
09-07-2002, 07:09 PM
hello,
I'm trying to delete the records in a table through a form.First, i'm displaying all the records and then at the end of each record set,there is a checkbox and when i check it, the record is set for deleted(Not actually deleted from the table)Now,i'm trying to display two buttons, cancel and delete.when i hit delete the record is permanently deleted and when i hit cancel, the record which is set for delete is cancelled .
I've been trying this since a week and i could'nt really succeed.Could somebody pls help me.
here is my code
<?php
//Database connection details
if ($HTTP_POST_VARS){
/*-- the form was submitted, lets process it --*/
/*-- get a count of how many ids we have to process --*/
$cnt = count($HTTP_POST_VARS['id']);
$delete_sql = "DELETE from TBL_RBSNEW where id=$RBS_ID";
$result = ibase_query($delete_sql);
/*-- cycle through the arrays and update the database table --*/
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;
$sql = "update TBL_RBSNEW 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]}";
if (count($delete))
$sql .= "RBS_DELETE = 'Y'";
$sql .= "where RBS_ID = {$HTTP_POST_VARS['id'][$cntr]}";
"where RBS_ID = {$HTTP_POST_VARS['id'][$cntr]}";
$results = ibase_query($sql);
if (!$results) {
/* the query failed*/
echo "Error executing the update statement.
Interbase Reported:".ibase_errmsg()."
".
"SQL=$sql
\n";
}
}
}
/*-- this section is always shown --*/
/*-- get all records from the table --*/
$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_RBSNEW';
$result_id = ibase_query($select_sql) or die('Error retrieving records from TBL_RBS.
Interbase Reported: '.ibase_errmsg());
?>
Edit 'N' Delete RBS</p>
<form name="editRBS" action="<?=$HTTP_SERVER_VARS['PHP_SELF']?>" method="POST">
<?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;
/*-- output this row in the table --*/
?>
<tr style="margin:0; padding:0;" align="left" valign="top">
<td width="156" height="23">
<input type="text" name="rfpi[<?=$counter?>]" value="<?=$rfpi?>">
</td>
<td width="154" height="23">
<input type="text" name="ip_address[<?=$counter?>]" value="<?=$ipaddress?>">
</td>
<td width="69" height="23">
<input type="checkbox" name="enrolment[<?=$counter?>]" value="1"<? if ($enrolment==1)echo "checked";?>>
</td>
<td width="65" height="23">
<input type="checkbox" name="ciphering[<?=$counter?>]" value="1" <? if ($ciphering==1)echo "checked";?>>
</td>
<td width="155" height="23">
<input type="text" name="mac_address[<?=$counter?>]" value="<?=$macaddress?>">
</td>
<td width="156" height="23">
<input type="text" name="subnet_mask[<?=$counter?>]" value="<?=$subnetmask?>">
</td>
<td width="156" height="23" align="left" valign="top">
<input type="text" name="router_ip[<?=$counter?>]" value="<?=$routerip?>">
</td>
<td width="156" height="23" align="left" valign="top">
<input type="text" name="tftp_server[<?=$counter?>]" value="<?=$tftpserver?>">
</td>
<td width="156" height="23" align="left" valign="top">
<input type="text" name="tftp_file[<?=$counter?>]" value="<?=$tftpfile?>">
</td>
<td width="69" height="23">
<?
if ($row->RBS_DELETE) {
echo"<input type=\"checkbox\" name=\"ok[$counter]\" value=\"1\">";
echo"<input type=\"checkbox\" name=\"cancel[$counter]\" value=\"1\">";
}
else
echo"<input type=\"checkbox\" name=\"delete\" value=\"1\">";
?>
</td>
</tr>
<?php
$old_values.=' <input type="hidden" name="id['.$counter.']" value="'.$row->RBS_ID.'">
';
$counter++;
}
?>
</table>
<?=$old_values?>
<input type="submit" name="submit" value="Update">
<input type="hidden" value="Reset">
</form>
</body>
</html>
I'm trying to delete the records in a table through a form.First, i'm displaying all the records and then at the end of each record set,there is a checkbox and when i check it, the record is set for deleted(Not actually deleted from the table)Now,i'm trying to display two buttons, cancel and delete.when i hit delete the record is permanently deleted and when i hit cancel, the record which is set for delete is cancelled .
I've been trying this since a week and i could'nt really succeed.Could somebody pls help me.
here is my code
<?php
//Database connection details
if ($HTTP_POST_VARS){
/*-- the form was submitted, lets process it --*/
/*-- get a count of how many ids we have to process --*/
$cnt = count($HTTP_POST_VARS['id']);
$delete_sql = "DELETE from TBL_RBSNEW where id=$RBS_ID";
$result = ibase_query($delete_sql);
/*-- cycle through the arrays and update the database table --*/
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;
$sql = "update TBL_RBSNEW 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]}";
if (count($delete))
$sql .= "RBS_DELETE = 'Y'";
$sql .= "where RBS_ID = {$HTTP_POST_VARS['id'][$cntr]}";
"where RBS_ID = {$HTTP_POST_VARS['id'][$cntr]}";
$results = ibase_query($sql);
if (!$results) {
/* the query failed*/
echo "Error executing the update statement.
Interbase Reported:".ibase_errmsg()."
".
"SQL=$sql
\n";
}
}
}
/*-- this section is always shown --*/
/*-- get all records from the table --*/
$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_RBSNEW';
$result_id = ibase_query($select_sql) or die('Error retrieving records from TBL_RBS.
Interbase Reported: '.ibase_errmsg());
?>
Edit 'N' Delete RBS</p>
<form name="editRBS" action="<?=$HTTP_SERVER_VARS['PHP_SELF']?>" method="POST">
<?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;
/*-- output this row in the table --*/
?>
<tr style="margin:0; padding:0;" align="left" valign="top">
<td width="156" height="23">
<input type="text" name="rfpi[<?=$counter?>]" value="<?=$rfpi?>">
</td>
<td width="154" height="23">
<input type="text" name="ip_address[<?=$counter?>]" value="<?=$ipaddress?>">
</td>
<td width="69" height="23">
<input type="checkbox" name="enrolment[<?=$counter?>]" value="1"<? if ($enrolment==1)echo "checked";?>>
</td>
<td width="65" height="23">
<input type="checkbox" name="ciphering[<?=$counter?>]" value="1" <? if ($ciphering==1)echo "checked";?>>
</td>
<td width="155" height="23">
<input type="text" name="mac_address[<?=$counter?>]" value="<?=$macaddress?>">
</td>
<td width="156" height="23">
<input type="text" name="subnet_mask[<?=$counter?>]" value="<?=$subnetmask?>">
</td>
<td width="156" height="23" align="left" valign="top">
<input type="text" name="router_ip[<?=$counter?>]" value="<?=$routerip?>">
</td>
<td width="156" height="23" align="left" valign="top">
<input type="text" name="tftp_server[<?=$counter?>]" value="<?=$tftpserver?>">
</td>
<td width="156" height="23" align="left" valign="top">
<input type="text" name="tftp_file[<?=$counter?>]" value="<?=$tftpfile?>">
</td>
<td width="69" height="23">
<?
if ($row->RBS_DELETE) {
echo"<input type=\"checkbox\" name=\"ok[$counter]\" value=\"1\">";
echo"<input type=\"checkbox\" name=\"cancel[$counter]\" value=\"1\">";
}
else
echo"<input type=\"checkbox\" name=\"delete\" value=\"1\">";
?>
</td>
</tr>
<?php
$old_values.=' <input type="hidden" name="id['.$counter.']" value="'.$row->RBS_ID.'">
';
$counter++;
}
?>
</table>
<?=$old_values?>
<input type="submit" name="submit" value="Update">
<input type="hidden" value="Reset">
</form>
</body>
</html>