Als je een checkbox aanvinkt (of meerdere) en je klikt op de knop 'Delete' dan worden die regels uit de tabel verwijderd.
Nu wil ik de knop 'Delete' vervangen door 'Update', dus als je een checkbox (of meerdere) aanvinkt, en als je dan op 'Update' klikt, dat 'status' automatisch gewijzigd wordt naar 'ja'.
Voorbeeld zoals het nu is:
http://www.pro-aviation.nl/test/database/index.php
Hieronder het gehele script. Het 'Delete' gedeelte staat helemaal onderaan. Ik kom er echter niet uit om daar een 'Update' van de maken.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$host="localhost"; // Host name
$username="xxxx"; // Mysql username
$password="xxxx"; // Mysql password
$db_name="xxxx"; // Database name
$tbl_name="xxxx"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="800" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="8" bgcolor="#FFFFFF"><strong><input name="delete" type="submit" id="delete" value="Delete Selection">
<a href="index.php?p=form&mode=add">Add New</a> </strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Registration</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Aircraft</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>C/N</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Airline</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Special</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Update</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" value="<?=$rows['id'];?>"></td>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['registratie']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['toestel']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['serial']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['maatschappij']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['speciaal']; ?></td>
<td bgcolor="#FFFFFF"><a href="<? echo "index.php?p=form&id=".$rows['id']."&mode=update"; ?>">Update</a></td>
</tr>
<?php
}
?>
<tr>
<td align="center" bgcolor="#FFFFFF"></td>
<td colspan="8" align="left" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete Selection"></td>
</tr>
<?
// Check if delete button active, start this
if(isset($_POST['delete'])){
foreach($_POST["checkbox"] as $key => $value)
{
$sql = "DELETE FROM $tbl_name WHERE id='$value'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>