Reply to Re: [PHP] Processing two post values

Your name:

Reply:


Posted by "Richard Lynch" on 10/23/05 03:58

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

[Back to original 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

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