You are here: Re: Dynamic Form « PHP Programming Language « IT news, forums, messages
Re: Dynamic Form

Posted by Jerim79 on 04/05/07 18:09

On Apr 5, 10:36 am, Tyno Gendo <you@localhost> wrote:
> Jerim79 wrote:
> > A new situation that has arised is that now the for loop, even though
> > it doesn't insert anything other than 0 to the database, it seems to
> > be stuck in an infinite loop. Here is the code:
>
> > <?php
>
> > if ($_SERVER["REQUEST_METHOD"] == "POST") {
> > $Number=$_POST['Number'];
> > echo $Number;
> > $Age[]=$_POST['Age'];
> > $Height[]=$_POST['Height'];
>
> > include ("../functions/db_conn.php");

>
> > for ($i=0; i <= $Number; $i++) {
> > $query="INSERT INTO Age(Age,Height)
> > VALUES('$Age[$i]','$Height[$i]')";
> > echo $Age[i], $Height[i];
> > $result = mysql_query($query) or die('Query failed: ' .
> > mysql_error());
> > }
>
> > There are two echo $Number commands, one is not pictured here as it is
> > at the bottom of the page. Both of these confirm that $Number equals
> > 2. I might try a while loop, to just see if that fixes anything. I
> > don't know why this infinite loop just appeared.
>
> Is the code cut and paste? its missing the $ off the i<= $Number

You guys are completely awesome. That was the problem. I have one
quick parting questions. I should probably just start a new thread,
but since you all seem to know your stuff, I thought I would ask here
first.

I have been playing around with the form, using radio buttons instead
of text boxes. The problem I am having, is that within the while loop
that displays the question for the number of times a user specifies,
all occurrences of that question use the same name for the radio
button. Here is the while loop:

while ($Number!=0){
<input type="radio" name="Age[]" value="20-30">20-30
<input type="radio name="Age[]" value="30-40">30-40
<input type="radio name"Age[]" value="40-50">40-50
$Number--;
}

Let's say someone entered 3 for $Number. When the loop executes it
would produce:

<input type="radio" name="Age[]" value="20-30">20-30
<input type="radio name="Age[]" value="30-40">30-40
<input type="radio name"Age[]" value="40-50">40-50

<input type="radio" name="Age[]" value="20-30">20-30
<input type="radio name="Age[]" value="30-40">30-40
<input type="radio name"Age[]" value="40-50">40-50

<input type="radio" name="Age[]" value="20-30">20-30
<input type="radio name="Age[]" value="30-40">30-40
<input type="radio name"Age[]" value="40-50">40-50

The problem is that with radio buttons, you can only choose one
option. With this code, it only allows the user to choose one option
from among the 9 listed, instead of one from each set. Since it really
needs to be radio buttons, I am trying to find a way to dynamically
name each set. Would something like this work:

<input type="radio name"Age<?php echo $Number ?>[]"
value="40-50">40-50

But that would seem to negate the whole need for arrays, which you all
were so patient in teaching me. This may be more of an HTML question
as how to define sets of radio buttons.

 

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

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