Admin Interface Checkboxes - connect to a function

Hello everybody,

I am working on an admin interface, where you have a list of database entries with checkboxes. In the end there are three drifferent buttons connected to three different functions. I need to get the id of the entry by clicking on the checkbox and then connect it somehow to the functions (functions are: delete, move to a database with different structure and send an e-mail). How do I pick up the id? And will irt work with more than one id? Here is my interface:

<?php $result = mysql_query("SELECT * FROM db1 ORDER BY name1")or die ('Error: '.mysql_error ()); ?>

//This is the list with the checkboxes

<?php while($show = mysql_fetch_array($result)) { $checkboxname=''.$show[id].'';?> <?php } ?>
<?php echo $show[name2]; ?> <?php echo $show[name1]; ?> <?php echo $checkboxname; ?>
//Those are the buttons I need to connet with the list

 

Date
Time

And here is the function “Delete” as an example:

$checkboxname=extract($_POST);
echo $checkboxname;//Has always the value 0 for some reason, although what I select has another id…
$myquery = “DELETE * FROM db1 WHERE id=’’.$checkboxname.’’”;
$result=mysql_query($myquery);
mysql_close();

Well, this just doen’t work… Can anybody help me?

Regards,
Veronika

For checkboxes, you should keep the following in mind:

  • You can just retrieve them using the same mechanism you use for your other form elements ($_POST, in your case)
  • You’re going to have to include the checkboxes in your form though (coz they’re above the form right now)
  • Checkboxes only exist as $_POST variables when they’re checked. If they’re not checked, their $_POST indexes will be uninitialized.
  • $_POST indexes of checked checkboxes will have the same value as the ‘value’ attribute of your checkboxes (which aren’t set in your case).
Sponsor our Newsletter | Privacy Policy | Terms of Service