daveh33 Posted January 24, 2008 Share Posted January 24, 2008 while ($row = mysql_fetch_array($result)) { $time = $row['time']; $tip = $row['tip']; echo "<br /><form method=\"post\" action=\"\"><p align=\"center\"> <b>Tip</b><input type=\"text\" name=\"tip\" value=\"$tip\"> <b>Time</b><input type=\"text\" name=\"time\" value=\"$time\"> <br /><input type=\"submit\" name=\"submit\" value=\"submit\"></form> <br />"; I have the above while statement - but how can I number the name fields instead of tip, as tip1, tip2, tip3 etc.. so they can be picked up as $_POST['tipx'] Link to comment https://forums.phpfreaks.com/topic/87584-while-statement-handeling-forms/ Share on other sites More sharing options...
acidglitter Posted January 24, 2008 Share Posted January 24, 2008 you could try this.. $tip_num=0; while ($row = mysql_fetch_array($result)) { $tip_num++; $time = $row['time']; $tip = $row['tip']; echo "<br /><form method=\"post\" action=\"\"><p align=\"center\"> <b>Tip</b><input type=\"text\" name=\"tip{$tip_num}\" value=\"$tip\"> <b>Time</b><input type=\"text\" name=\"time\" value=\"$time\"> <br /><input type=\"submit\" name=\"submit\" value=\"submit\"></form> <br />"; do you want more than one form? because how it looks now its going to echo the entire form code for every row Link to comment https://forums.phpfreaks.com/topic/87584-while-statement-handeling-forms/#findComment-447989 Share on other sites More sharing options...
wildteen88 Posted January 24, 2008 Share Posted January 24, 2008 while ($row = mysql_fetch_array($result)) { $time = $row['time']; $tip = $row['tip']; echo "<br /><form method=\"post\" action=\"\"><p align=\"center\"> <b>Tip</b><input type=\"text\" name=\"tip\" value=\"$tip\"> <b>Time</b><input type=\"text\" name=\"time\" value=\"$time\"> <br /><input type=\"submit\" name=\"submit\" value=\"submit\"></form> <br />"; I have the above while statement - but how can I number the name fields instead of tip, as tip1, tip2, tip3 etc.. so they can be picked up as $_POST['tipx'] Use the following code instead: <b>Tip</b><input type=\"text\" name=\"tip\" value=\"{$tip}[]\"> <b>Time</b><input type=\"text\" name=\"time\" value=\"$time\"> Ending a field name with [] will make the browser submit it as an array. So when you retrieve $_POST['tip'], it will hold an array rather than a string value. So $_POST['tip][0] will be the first field, $_POST['tip'][1] will be the second an so on. Link to comment https://forums.phpfreaks.com/topic/87584-while-statement-handeling-forms/#findComment-448035 Share on other sites More sharing options...
daveh33 Posted January 24, 2008 Author Share Posted January 24, 2008 OK - but do you mean name={$tip}[] & not the value? Link to comment https://forums.phpfreaks.com/topic/87584-while-statement-handeling-forms/#findComment-448056 Share on other sites More sharing options...
wildteen88 Posted January 25, 2008 Share Posted January 25, 2008 OK - but do you mean name={$tip}[] & not the value? Oops! O_o yeah I meant the name of the field not the value sorry, code corrected: <b>Tip</b><input type=\"text\" name=\"tip[]\" value=\"$tip\"> <b>Time</b><input type=\"text\" name=\"time\" value=\"$time\"> Link to comment https://forums.phpfreaks.com/topic/87584-while-statement-handeling-forms/#findComment-449053 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.