Re: Multiline data Insert Into table from a generated form?

From: Date: Wed, 02 Feb 2005 11:32:32 +0000
Subject: Re: Multiline data Insert Into table from a generated form?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-207884@lists.php.net to get a copy of this message
> Code: > print '<table width="545" border="0" cellspacing="0" > cellpadding="0" > align="center"><tr>'; > print '<form action="test1.php" method="POST">'; > $i = 1; > while ($i <= $tour_days) { > print '<input type="hidden" name="tourdays" > value="'.$tour_days.'">'; > print '<input type="hidden" name="tourid'.$i.'" > value="'.$tour_id.'">'; > $days = ("Day&nbsp;0".$i); > print $days; > print '<input type="hidden" name="dayno'.$i.'" > value="'.$days.'">'; > print '</td>'; > print '<input type="text" name="fromto'.$i.'" > size="50"></td>'; > print '<input type="text" name="bld'.$i.'" > size="10"></td></tr>'; > print '<tr><td colspan="3">'; > print '<textarea name="descrip'.$i.'" rows="5" > cols="80" > wrap="virtual"></textarea></td></tr>'; > $i++; > } > print '</table>'; > print "<input type=\"submit\" > value=\"submit!\">\n</form>\n"; Change the field names to arrays (i.e. "tourid".$i becomes tourid[] When you POST loop through the array: while($c=0;$c<count($_POST['tourid']):$c++){ If($_POST['tourid'][$c]!=""...){ $sql = "INSERT INTO reservations ('tourid'...) VALUES ('{$_POST['tourid'][$c]}'...)\n"; } }

« previous php.general (#207884) next »