PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I got a script that outputs all records from a database, beside each record there is a checkbox....When i select the record from the results by pressing the checkbox it passes to another script. That script will delete the record from the database when it recieves the ID from, the checkbox...
Thats fine, the problem is when i select more than one record to delete it will only delete one record not the selected records..
So basically what i want the script to do is to be able to delete more than one record at a time.. Cheers all help apperciated.
<?PHP include 'opendb.php'; ?>
<?PHP include 'header.php'; ?>
<?php
$FlightID = $_POST['FlightID'];
$status = "OK"; // setting the flag for form validation
$msg=""; // error message string is blank
// Now let us check if name is entered or not
if(strlen($FlightID) < 1 ){ // if name is less than two char length
$msg .="<center>Please select a flight</center><BR>";
$status="NOT OK";
}
if($status<>"OK"){ // if form validation is not passed
echo "<BR><BR>";
echo $msg. "<br><center><input type='button' value='Retry' onClick='history.go(-1)'></center><br><br><br>";
}else{
$query="DELETE Flights WHERE FlightID='$FlightID '";
mssql_query($query);
echo "Records Updated<p><input type='button' value='Back' onClick='history.go(-1)'>";
}
mssql_close();
?>
<?PHP include 'footer.php'; ?>
Name the field correctly i.e. "foo[]" The important part being the brackets as PHP will create an array automatically. It will be accessed by $_POST['foo']. You will need to validate each value given, escape it properly (so it isn't susceptible to SQL injection) and finally create a good query. We often suggest to modify a flag in the record instead of actually deleting it.
<?PHP include 'opendb.php'; ?>
<?PHP include 'header.php'; ?>
<?php
$FlightID = $_POST['FlightID']
$status = "OK"; // setting the flag for form validation
$msg=""; // error message string is blank
// Now let us check if name is entered or not
if(strlen($FlightID) < 1 ){ // if name is less than two char length
$msg .="<center>Please select a flight</center><BR>";
$status="NOT OK";
}
if($status<>"OK"){ // if form validation is not passed
echo "<BR><BR>";
echo $msg. "<br><center><input type='button' value='Retry' onClick='history.go(-1)'></center><br><br><br>";
}else{
if(isset($_POST['FlightID']))
{
foreach($_POST['FlightID'] as $k=>$k1)
{
$query="DELETE Flights WHERE FlightID=$k1";
}
}
mssql_query($query);
echo "Records Updated<p><input type='button' value='Back' onClick='history.go(-1)'>";
}
mssql_close();
?>
<?PHP include 'footer.php'; ?>