| 
	
 | 
 Posted by Alliss on 06/11/10 11:38 
Thanks Tyrone 
 
I have sorted itout now.   2 silly errors I was making 
 
    In     $sql = "--- VALUES  ('$lastName[n]','$firstName[n])"; 
                 instead of [n]  I should have used [$n] 
 
   <input type='submit'  name='lastName[]'   value=' Brown '> 
            should have been 
   <input type='text'  name='lastName[]'   value=' Brown '> 
 
"Tyrone Slothrop" <ts@paranoids.com> wrote in message 
news:e9ckt15qgl83ad1s1dh1kjsup8biogtdqi@4ax.com... 
> 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. 
>
 
  
Navigation:
[Reply to this message] 
 |