Reply to Re: Problem getting array values from form

Your name:

Reply:


Posted by Tyrone Slothrop on 10/12/01 11:38

On Sat, 28 Jan 2006 02:40:05 +1300, "Alliss" <a11iss@wonderland.com>
wrote:

>I have a dynamically generated form which produces a series controls like
>these.
>
> <input type='submit' name='lastName[]' value=' Brown '>
> <input type='submit' name='firstName[]' value=' Bill '>
>
>I end up with about 90 elements in each array.
>I submit the form using
><form method="post" action ="<?php echo $PHP_SELF ?> " >
>
>After the form is submitted and I test to find the values in the arrays they
>are empty.
>I want to be able to insert the individual values from the arrays into a
>database table.
>I have tried numerous ways to do this but this will give you an idea of what
>I am aiming for:
>(the value of $insertData is the number of elements in the arrays coming
>from the form)
>
>if($insertData){
> for($n=0; $n<$insertData; $n++){
> $sql = "INSERT INTO contacts (lastName,firstName) VALUES
>('$lastName[n]','$firstName[n])";
> ...
>
>I would be grateful if someone can tell me how I should be submitting and
>then reading the values of lastName and firstName.
>
>Al

I am a bit confused on what you are doing here, but you have a number
of problems with how you are evaluating your arrays.

First, surround your array vars with curly brakets in the SQL
statement. The common syntax would be:
{$_POST['lastName'][$n]}

Also, you want to count the number of elements of the arrays by a
count of the names:
for ($n=0;$n<count($_POST['firstName']),$n++)...

To see what is being posted for debugging, use print_r() function:

echo "<pre>";
print_r($_POST);
echo "</pre>";

Hope this helps.

[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

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