> I'm making the administration part of a site which handles categories,
> sub categories and products. Inside the "Categories" part, there's a
> "List categories" button which gives a list of the categories and sub
> categories when pressed. Along with each category, there's a "Delete"
> button that, when pressed, it's supposed to delete that category from
> the DB. The problem here is that the lists is made dynamically using a
> FOR loop and is being placed inside a FORM so the action is handled
> through an ACTION="" tag.
> 
> Now, the ACTION tag points to a php file which deletes the desired row
> in the DB. The question is how to tell that php file (through GET or
> POST) which row to delete... My first shot was to name each "Delete"
or
> submit button inside form like "delcategory?catid=0001" but then the
> POST wasn't reading that...
> 
> Any thoughts? Thanks in advance,

You could use a bunch of forms, if you want to use a button. Since
you're using a while() loop, it wouldn't be a big deal...

While(fetching_from_db)
{
  <form>
  <hidden cat_id>
  Other data
  <submit button>
  </form>
}

Then the delete button on each row is for it's own form with a hidden
cat_id element that you can use to tell which row to delete.

Even better would be to use checkboxes, so you can delete multiple rows
at one. Name them <input type="checkbox" name="delete[]"
value="<?=$cat_id?>">

And when it's submitted all of the checked boxes will be in
$_POST['delete'], so you can do this:

$delete_ids = implode(",",$_POST['delete']);
$query = "DELETE FROM table WHERE ID IN ($delete_ids)";

Add in your own validation, of course...

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to