hello,
I am using this script to update and delete the records in a table.
I am trying to first set a value to a column called STD_DELETE.So, first, when i display the records, and when i check a checkbox and hit submit, the record is marked for deletion. i.e a value is set to 0 or 1 for the column STD_DELETE.
Then, i would like to delete the record based on this column value.
could somebody pls help me out what is wrong with my script.
<?php
// here is the 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']);
for($cntr=0;$cntr<$cnt;$cntr++) {
if (isset($select)){
foreach($select as $name => $val) {
echo "Record $name = $val<br>\n";
}
}else{
echo "No selection made!";
}
$counter = "counter";
$update_sql = "update TBL_STUDENTS SET ".
"STD_LASTNAME = '{$HTTP_POST_VARS['last_name'][$cntr]}', ".
"STD_FIRSTNAME = '{$HTTP_POST_VARS['first_name'][$cntr]}', ".
"STD_MAJOR = '{$HTTP_POST_VARS['major'][$cntr]}' ";
if ($HTTP_POST_VARS['select'][$cntr] == "on") { $sql.= "STD_DELETE = '1'"; }
$sql.= "where STD_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 STD_ID, STD_FIRSTNAME, STD_LASTNAME, STD_MAJOR from TBL_STUDENTS';
$result_id = ibase_query($select_sql) or die('Error retrieving records from TBL_RBS.<br />Interbase Reported: '.ibase_errmsg());
?>
<html>
<head>
</head>
<p style="line-height:100%; margin-top:0; margin-bottom:0;"><h1>
<form name="editstudents" action="<?=$HTTP_SERVER_VARS['PHP_SELF']?>" method="POST">
<table cellpadding="0" cellspacing="0" width="909">
<tr style="margin:0; padding:0;" align="left" valign="top">
<td width="154">
First name
</td>
<td width="154">
Last name
</td>
<td width="69">
Major
</td>
<td width="65">
Delete
</td>
</tr>
<?php
$counter=0;
$old_values=null;
while ($row = ibase_fetch_object($result_id)) {
$lastname=$row->STD_LASTNAME;
$firstname=$row->STD_FIRSTNAME;
$major=$row->STD_MAJOR;
/*-- output this row in the table --*/
?>
<tr style="margin:0; padding:0;" align="left" valign="top" class="rbsnormal">
<td width="156" height="23">
<input type="text" name="last_name[<?=$counter?>]" value="<?=$lastname?>">
</td>
<td width="154" height="23">
<input type="text" name="first_name[<?=$counter?>]" value="<?=$firstname?>">
</td>
<td width="69" height="23">
<input type="text" name="major[<?=$counter?>]" value="<?=$major?>"
</td>
<td width="69" height="23">
<INPUT type=checkbox name="select[<?=$counter?>]" value="delete">
</td>
</tr>
<?php
$old_values.=' <input type="hidden" name="id['.$counter.']" value="'.$row->STD_ID.'">
';
$counter++;
}
?>
</table>
<?=$old_values?>
<input type="submit" name="submit" value="Update">
</form>
</body>
</html>
Thanks in advance