Re: Checkbox & Hidden Field to Delete Row

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thursday 01 June 2006 12:58, Rahul S. Johari wrote:
> Ave,
>
> I¹m stuck on a problem here.
> I have a file manager kind of application and I¹m trying to add the
> functionality to delete multiple files.
>
> Basically, there¹s a bunch of rows generated dynamically. Each row has a
> checkbox for ³Delete² option, and a hidden field which contains the name of
> the File associated with the record. If a user checks a checkbox to delete
> certain rows, it should be able to delete those rows from mySQL as well as
> delete the files associated with that record.
>
> I created both the checkboxes & the hidden fields to be Arrays. I run a
> loop to delete all rows (based on ID¹s) where the checkbox was Checked. It
> does that part fine... The problem is linking the Filename array to the
> Checkbox Array. It deletes the first two files uploaded no matter what rows
> are checked. Basically, the Filename array is not associating with the
> Checkbox array. So if  a person checks the 3rd and 5th checkbox... The 3rd
> & 5th row is deleted from mySQL, but the 1st and 2nd file is deleted, not
> the 3rd & 5th.
>
> Rahul S. Johari

The problem is coming from how checkboxes submit their information to the 
form.  Only the checked checkboxes will actually send data.  The unchecked 
ones will not send anything.  Hidden fields differ, in that they ALWAYS send 
their data.  This is probably causing a mis-match between the two arrays.  
You could verify that by doing a var_dump on the arrays before you delete 
anything.

I would suggest that since you keep a record of the file in the database, 
include the file location in that database record.  Then before you delete 
it, get the file name, delete the file, then delete the record.  I think that 
would save you a bunch of headaches.

-- 
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
www.americanstudentloan.com
1.800.575.1099

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux