kalevra Posted September 8, 2008 Share Posted September 8, 2008 I have a script that makes a html form like this: $i=1; while ($i<=5){ echo "<input type="text" name="name$i"><br />"; } Now the script getting the form looks something like this: while($i<=5){ echo "<tr><td>Name:</td><td> $name$i </td></tr>"; } The problem comes from the "$name$i" which doesn't behave like I would like it to. I would like the source echo'ed from the script to be something like: <tr><td>Name:</td><td> $name1 </td></tr> <tr><td>Name:</td><td> $name2 </td></tr> <tr><td>Name:</td><td> $name3 </td></tr> <tr><td>Name:</td><td> $name4 </td></tr> <tr><td>Name:</td><td> $name5 </td></tr> And actually get all the values from the different input fields echo'ed. Link to comment https://forums.phpfreaks.com/topic/123294-quick-variable-question/ Share on other sites More sharing options...
tmbrown Posted September 8, 2008 Share Posted September 8, 2008 change echo "<input type="text" name="name$i"> to echo "<input type=\"text\" name=\"name".$i."\">"; Link to comment https://forums.phpfreaks.com/topic/123294-quick-variable-question/#findComment-636734 Share on other sites More sharing options...
kalevra Posted September 8, 2008 Author Share Posted September 8, 2008 The problem is when the form is sent to the script, I would like to get the values of all the $name ($name1, $name2, $name3,...) in a loop, but doing it using: $name$i and incrementing $i doesn't work. I assume that is because when the script runs it gives the value of $name (which is nothing) and then the value of $i (which is 1,2,3,4,5) instead of giving the value of $name1,$name2... etc. Link to comment https://forums.phpfreaks.com/topic/123294-quick-variable-question/#findComment-636750 Share on other sites More sharing options...
tmbrown Posted September 8, 2008 Share Posted September 8, 2008 is $name an actual variable or do you just wish to display "name"? Link to comment https://forums.phpfreaks.com/topic/123294-quick-variable-question/#findComment-636754 Share on other sites More sharing options...
PFMaBiSmAd Posted September 8, 2008 Share Posted September 8, 2008 You need to use an array, not sequentially named variables. Link to comment https://forums.phpfreaks.com/topic/123294-quick-variable-question/#findComment-636773 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.