You are here: Re: Help with $_POST and $_SERVER['PHP_SELF'] please. « PHP Programming Language « IT news, forums, messages
Re: Help with $_POST and $_SERVER['PHP_SELF'] please.

Posted by Jerry Stuckle on 05/20/06 16:30

Dynamo wrote:
> I kinda guessed that if I used a new php page that the original $_POST array
> would be lost. However, I mistakenly thought that if I used $_SERVER['PHP_SELF']
> as the action for the form that the array would still be stored. It appears that
> that is not the case. So the problem remains of how to EASILY pass the array
> from the first page to the next. I had already tried using
>
> <input type="hidden" name="delete" value="<?php echo $_POST['delete']; ?>">
>
> but it didn't work. When I debugged by using
>
> <?php
> echo "<pre>\n";
> print_r($_POST['delete']);
> echo "</pre>\n";
> ?>
>
> on the second page all I got was the word "Array", hence when that was inserted
> into the delete query I got
>
> $query1 = "DELETE FROM Catalogue WHERE id = Array"
>
> So I'm hazarding another guess that my hidden field input should be something
> morelike this
> <?php
> for each (value stored in the array){
> ?>
> <input type="hidden" name="delete[]" value="<?php echo (value stored in array);
> ?>">
> <?php
> }
> ?>
>
> Only problem is I'm not sure what goes into the (value stored in array) part of
> the code. Any help greatly appreciated. Is there an easier way of passing the
> array?
>
> Regards
> Dynamo
>
>
>
>
>
> In article <pan.2006.05.20.02.37.48.82620@bens-house.org.uk>, Ben Holness
> says...
>
>>Dynamos comments are totally valid, but on the basis that you stripped all
>>that stuff out, you just need to add a hidden input here to make it work...
>>
>>(Note: Example typed and not tested)
>>
>>
>>><?php
>>>$delete = '( id = ' . implode(' OR id = ', $_POST['delete'] ) . ' ) ';
>>>if (!isset($_POST['submit']))
>>>{
>>>// Then display the records that were marked for deletion ?>
>>><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
>>
>>** Hidden input here **
>><input type="hidden" name="delete" value="<?php echo $_POST['delete']; ?>">
>>
>>><p> align="center"><font face="Arial" size="2"><b>Are you sure you wish to
>>>continue?</b></font></p>
>>><p align="center"><input type="submit" name="submit" value="Yes I want
>>>to delete these records"></p>
>>></form>
>>
>>[snip]
>>
>>
>>Cheers,
>>
>>Ben
>
>

Ben,

The problem here is:

value="<?php echo $_POST['delete'];

If $_POST['delete'] is an array, the result will be

value="Array"

in your page. You can see that if you view the source code for your page in
your browser.

Since $_POST['delete'] is an array, you have a couple of choices. You can
serialize the array before storing it, then use htmlentities() in case you have
other chars in the string (i.e. a " mark).

The way I prefer is to store it in the session. Just call session_start() at
the beginning of each page where you need sessions (before ANY output -
including whitespace - is generated) and store it in the session, i.s.

<?php
start_session();
(perhaps other stuff here, i.e. validation code)
$_SESSION['delete'] = $_POST['delete'];
?>

Then the next time through you can get it from $_SESSION['delete'].

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

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

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