Re: Processing two post values

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

 



On Sat, October 22, 2005 7:14 pm, Shaun wrote:
> For each room I need to insert the values to the database, however I
> cant
> think of a way to do this. All one can do with php is a foreach on the
> $_POST values whereas I need to process two at a time i.e. one insert
> of the
> x and y values per room. Here is the form I have created:

Actually, PHP will let you process the variables in any manner you see
fit. :-)

What I would recommend in THIS case is to take advantage of your room
numbers to do more like this:

> <form action="<?php action=<?php echo $frm['action'];
> ?>&property_id=<?php
> echo $_GET['property_id']; ?>" method="post">
>  <table>
>  <tr>
>   <?php
>    $i = 1;
>    while( $i <= $frm["Number_Of_Bedrooms"] ){
>   ?>
>   <tr>
>    <td>Bedroom <?php echo $i ?>
>    <td>X:<input name="bedroom_<?php echo $i ?>_x" type="text" /></td>
>    <td>Y:<input name="bedroom_<?php echo $i ?>_y" type="text" /></td>

<input name="bedroom_x[<?php echo $i?>]" />
<input name="bedroom_y[<?php echo $i?>]" />

At the other end, when you process these, you'll have:

$property_id = $_POST['propery_id'];
$bedroom_x = $_POST['bedroom_x'];
$bedroom_y = $_POST['bedroom_y'];
while (list($i, $x) = each($bedroom_x)){
  $y = $bedroom_y[$i];
  echo "Bedroom $i: ($x, $y)<br />\n";
}

Note that PHP is one of the FEW languages that lets you use arrays as
NAME= in the HTML form and you can do something useful with it.

ASP don't do that.

JavaScript will choke on those names, most likely.

So, in reality, it's PHP's flexibility in processing of POST data that
is going to make this simple and natural rather than contrived and
complex.

NOTE:
This sample code contains no error-checking, data scrubing, nor
data-vaildation.

That's all got to be added by you.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
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