You are here: Re: Newbie - Help please with printing $_POST array « PHP Programming Language « IT news, forums, messages
Re: Newbie - Help please with printing $_POST array

Posted by David Haynes on 05/18/06 15:35

Dynamo wrote:
> Many Thanks,
>
> I had already tried that but it didn't work. All I got was an empty array (i.e.
> array()). Then I realised that because I hadn't actually "checked" any of the
> records on the previous page that of course the array WOULD be empty. So now
> having "checked" 3 records on the previos page I get the following result.
>
> Array
> (
> [1] => ON
> [61] => ON
> [62] => ON
> )
>
> So now I want to use the information stored in the $_POST array to delete
> records from mysql table. In the above example I would want the records where id
> = 1,61 and 62 to be deleted from the table named Catalogue. How would I
> incorporate the information stored in S_POST to complete the code below.
>
> $query1="DELETE FROM Catalogue WHERE id = ?";
> mysql_query($query1) or die("Failed Query of " . $query1);
>
> Regards
> Dynamo
>
>
> In article <qPXag.48244$IE1.4745@fe12.usenetserver.com>, David Haynes says...
>> <?php
>> echo "<pre>\n";
>> print_r($_POST);
>> echo "</pre>\n";
>> ?>
>>
>> -david-
>>
>
>
A trick when using checkboxes is to use a hidden field to record the
'off' value, then have the checkbox.

For example:
<?php
foreach( $keys as $key ) {
?>
<input type="hidden" name="<?php echo $key;?>" value="OFF">
<input type="checkbox" name="<?php echo $key;?>">
<?php
}
?>

If the checkbox is checked the value will be 'ON'; if the checkbox is
not set, the value will be whatever you set the hidden value to. ('OFF'
in the example)

To delete as per what you have shown:

foreach( $_POST as $key => $value ) {
if( $value == 'ON' ) {
$del = "delete from catalogue where id = $key";
mysql_query($del) or die("...");
}
}

-david-

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация