Re[2]: [PHP] Delete Multiple Records From Checkboxes

2004-05-26 Thread Tom Rogers
Hi,

Thursday, May 27, 2004, 3:07:28 PM, you wrote:

AP> On May 26, 2004, at 7:55 PM, Tom Rogers wrote:

>> Hi,
>>
>> Thursday, May 27, 2004, 11:34:03 AM, you wrote:
>> AP> I've checked the archives and several other sources, but still 
>> can't
>> AP> seem to make this work.
>>
>> AP> I have a form with checkboxes to designate records to be deleted
>> from
>> AP> the mysql database. The pertinent form code is:
>>
>> AP> > "\">
>>
>> AP> The processing code is:
>>
>> if (count($del) >> 0){
>> AP>  for ($i=0;$i>  
>> AP>  $query = "DELETE FROM ref_events_reg WHERE id = '$del[$i]'";
>> AP> }
>> AP> }
>>
>> AP> Echoing the query produces:
>>
>> AP> DELETE FROM ref_events_reg WHERE id = A
>>
>> AP> I've also tried the following:
>>
>> AP> $query = "DELETE FROM ref_events_reg WHERE id IN ('" . 
>> implode("','",
>> AP> addslashes($del)) . "')";
>>
>> AP> This one produces a warning:
>>
>> AP> Warning: implode(): Bad arguments.
>>
>> AP> and the following query:
>>
>> AP> DELETE FROM ref_events_reg WHERE id IN ('')
>>
>> AP> Both attempts fail to delete any records even though several 
>> records
>> AP> are checked.
>>
>> AP> Where have I gone wrong?
>>
>> AP> Thanks.
>>
>> AP> Albert Padley
>>
>>
>> change it to
>>
>>
>>
>>Then you can do something like
>>
>>foreach($del as $id=>$val){
>>  $query = "DELETE FROM ref_events_reg WHERE id = '$id'";
>>  //do query
>>}
>>
>> -- 
>> regards,
>> Tom
>>
AP> Tom,

AP> When I tried this I received a warning - Warning: Invalid argument
AP> supplied for foreach()
AP> and, of course, no records were deleted.

AP> Albert Padley


you would need to add a bit of code, that was very rough, I assumed you
got $del from $_POST

if(isset($_POST) && is_array($_POST['del'])){
  foreach($_POST['del'] as $id=>$val){
.
.
.
  }
}

-- 
regards,
Tom

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



Re: [PHP] Delete Multiple Records From Checkboxes

2004-05-26 Thread Albert Padley
On May 26, 2004, at 11:17 PM, Albert Padley wrote:
On May 26, 2004, at 11:16 PM, Curt Zirzow wrote:
* Thus wrote Albert Padley ([EMAIL PROTECTED]):

The processing code is:
if (count($del) > 0){
for ($i=0;$iI think you need to take a step back and figure out where the $del
variable is comming from.
Both solutions that have been provided should have worked if $del
was really an array.
Curt
--
"I used to think I was indecisive, but now I'm not so sure."
Curt,
I agree. I did a var_dump() with the following result:
array(2) {  ["del"]=>  array(2) {  [0]=>  string(2) "15"  [1]=>  
string(2) "16"  }  ["submit"]=>  string(6) "Delete" }

"15" and "16" are the correct id's for the records I'm trying to 
delete. However, when I echo $del[0] it returns "A" and when I echo 
$del[1] it returns "r" which happen to be the first 2 character in 
Array. So what gives?

Albert Padley
John, Tom and Curt,
I found that I had an include of functions that was somehow mucking 
things up. When I removed the functions page, all 3 of your solutions 
worked.

Thank you all for taking the time to assist.
Albert Padley
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Delete Multiple Records From Checkboxes

2004-05-26 Thread Albert Padley
On May 26, 2004, at 11:16 PM, Curt Zirzow wrote:
* Thus wrote Albert Padley ([EMAIL PROTECTED]):

The processing code is:
if (count($del) > 0){
for ($i=0;$iI think you need to take a step back and figure out where the $del
variable is comming from.
Both solutions that have been provided should have worked if $del
was really an array.
Curt
--
"I used to think I was indecisive, but now I'm not so sure."
Curt,
I agree. I did a var_dump() with the following result:
array(2) {  ["del"]=>  array(2) {  [0]=>  string(2) "15"  [1]=>  
string(2) "16"  }  ["submit"]=>  string(6) "Delete" }

"15" and "16" are the correct id's for the records I'm trying to 
delete. However, when I echo $del[0] it returns "A" and when I echo 
$del[1] it returns "r" which happen to be the first 2 character in 
Array. So what gives?

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


Re: [PHP] Delete Multiple Records From Checkboxes

2004-05-26 Thread Curt Zirzow
* Thus wrote Albert Padley ([EMAIL PROTECTED]):
> 
> 
> 
> The processing code is:
> 
> if (count($del) > 0){
>   for ($i=0;$i   
>   $query = "DELETE FROM ref_events_reg WHERE id = '$del[$i]'";
> }
> }

I think you need to take a step back and figure out where the $del
variable is comming from.

Both solutions that have been provided should have worked if $del
was really an array.


Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

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



Re: [PHP] Delete Multiple Records From Checkboxes

2004-05-26 Thread Albert Padley
On May 26, 2004, at 7:55 PM, Tom Rogers wrote:
Hi,
Thursday, May 27, 2004, 11:34:03 AM, you wrote:
AP> I've checked the archives and several other sources, but still 
can't
AP> seem to make this work.

AP> I have a form with checkboxes to designate records to be deleted 
from
AP> the mysql database. The pertinent form code is:

AP> 

AP> The processing code is:
if (count($del) >> 0){
AP>  for ($i=0;$i  $query = "DELETE FROM ref_events_reg WHERE id = '$del[$i]'";
AP> }
AP> }
AP> Echoing the query produces:
AP> DELETE FROM ref_events_reg WHERE id = A
AP> I've also tried the following:
AP> $query = "DELETE FROM ref_events_reg WHERE id IN ('" . 
implode("','",
AP> addslashes($del)) . "')";

AP> This one produces a warning:
AP> Warning: implode(): Bad arguments.
AP> and the following query:
AP> DELETE FROM ref_events_reg WHERE id IN ('')
AP> Both attempts fail to delete any records even though several 
records
AP> are checked.

AP> Where have I gone wrong?
AP> Thanks.
AP> Albert Padley
change it to
   
   Then you can do something like
   foreach($del as $id=>$val){
 $query = "DELETE FROM ref_events_reg WHERE id = '$id'";
 //do query
   }
--
regards,
Tom
Tom,
When I tried this I received a warning - Warning: Invalid argument 
supplied for foreach()
and, of course, no records were deleted.

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


Re: [PHP] Delete Multiple Records From Checkboxes

2004-05-26 Thread Albert Padley
On May 26, 2004, at 8:01 PM, John W. Holmes wrote:
Albert Padley wrote:
I've checked the archives and several other sources, but still can't 
seem to make this work.
I have a form with checkboxes to designate records to be deleted from 
the mysql database. The pertinent form code is:

The processing code is:
if (count($del) > 0){
for ($i=0;$i
$query = "DELETE FROM ref_events_reg WHERE id = 
'$del[$i]'";
}
}
Echoing the query produces:
DELETE FROM ref_events_reg WHERE id = A
Should be:
$query = "DELETE FROM ref_events_reg WHERE id = '{$del[$i]}'";
or
$query = "DELETE FROM ref_events_reg WHERE id = '".$del[$i]."'";
--
---John Holmes...
John,
Sorry, same result. No records deleted. Echoing the query returns:
DELETE FROM ref_events_reg WHERE id = 'A'
However, the id should be an integer. A var_dump() returns:
array(2) {  ["del"]=>  array(2) {  [0]=>  string(2) "15"  [1]=>  
string(2) "16"  }  ["submit"]=>  string(6) "Delete" }

Further, when I echo $del[0], it returns -- 'A' while $del[1] returns 
'r'. Just $del returns 'Array'.

Still working on it.
Albert Padley
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Delete Multiple Records From Checkboxes

2004-05-26 Thread John W. Holmes
Albert Padley wrote:
I've checked the archives and several other sources, but still can't 
seem to make this work.

I have a form with checkboxes to designate records to be deleted from 
the mysql database. The pertinent form code is:


The processing code is:
if (count($del) > 0){
for ($i=0;$i

$query = "DELETE FROM ref_events_reg WHERE id = '$del[$i]'";
}
}

Echoing the query produces:
DELETE FROM ref_events_reg WHERE id = A
Should be:
$query = "DELETE FROM ref_events_reg WHERE id = '{$del[$i]}'";
or
$query = "DELETE FROM ref_events_reg WHERE id = '".$del[$i]."'";
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals – www.phparch.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Delete Multiple Records From Checkboxes

2004-05-26 Thread Tom Rogers
Hi,

Thursday, May 27, 2004, 11:34:03 AM, you wrote:
AP> I've checked the archives and several other sources, but still can't
AP> seem to make this work.

AP> I have a form with checkboxes to designate records to be deleted from
AP> the mysql database. The pertinent form code is:

AP> 

AP> The processing code is:

if (count($del) >> 0){
AP> for ($i=0;$i $query = "DELETE FROM ref_events_reg WHERE id = '$del[$i]'";
AP> }
AP> }

AP> Echoing the query produces:

AP> DELETE FROM ref_events_reg WHERE id = A

AP> I've also tried the following:

AP> $query = "DELETE FROM ref_events_reg WHERE id IN ('" . implode("','",
AP> addslashes($del)) . "')";

AP> This one produces a warning:

AP> Warning: implode(): Bad arguments.

AP> and the following query:

AP> DELETE FROM ref_events_reg WHERE id IN ('')

AP> Both attempts fail to delete any records even though several records
AP> are checked.

AP> Where have I gone wrong?

AP> Thanks.

AP> Albert Padley


change it to

   

   Then you can do something like

   foreach($del as $id=>$val){
 $query = "DELETE FROM ref_events_reg WHERE id = '$id'";
 //do query
   }

-- 
regards,
Tom

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



[PHP] Delete Multiple Records From Checkboxes

2004-05-26 Thread Albert Padley
I've checked the archives and several other sources, but still can't 
seem to make this work.

I have a form with checkboxes to designate records to be deleted from 
the mysql database. The pertinent form code is:


The processing code is:
if (count($del) > 0){
for ($i=0;$i
Echoing the query produces:
DELETE FROM ref_events_reg WHERE id = A
I've also tried the following:
$query = "DELETE FROM ref_events_reg WHERE id IN ('" . implode("','", 
addslashes($del)) . "')";

This one produces a warning:
Warning: implode(): Bad arguments.
and the following query:
DELETE FROM ref_events_reg WHERE id IN ('')
Both attempts fail to delete any records even though several records 
are checked.

Where have I gone wrong?
Thanks.
Albert Padley
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php