fireice87 Posted October 15, 2007 Share Posted October 15, 2007 Intro: I a have a form for users to enter details. Before the form is shown the user enters a number of values they need to enter. So the amount the user enters first is the anount of rows the user is given to enter there details. To do this iv used a while loop and a $count variable. Problem: My problem is with echoing the form. I must be doing it in a completly non standard way as allthough firefox displays it perfectely ie doesnt display it at all. My Code: <form id="addgig" name="addgig" method="post" action="gigstore.php"> <table border="0" cellspacing="1"> <?php while($count < $Howmany) { echo "<tr height=\"22px\">\n"; echo "<td width=\"55px\" align=\"left\" valign=\"top\">"; echo "<select name=\"Day\">"; echo "<option value=$Day>$Day</option>"; echo "<option value=\"01\">01</option>"; echo "<option value=\"02\">02</option>"; echo "<option value=\"03\">03</option>"; echo "<option value=\"04\">04</option>"; echo "<option value=\"05\">05</option>"; echo "<option value=\"06\">06</option>"; echo "<option value=\"07\">07</option>"; echo "<option value=\"08\">08</option>"; echo "<option value=\"09\">09</option>"; echo "<option value=\"10\">10</option>"; echo "<option value=\"11\">11</option>"; echo "<option value=\"12\">12</option>"; echo "<option value=\"13\">13</option>"; echo "<option value=\"14\">14</option>"; echo "<option value=\"15\">15</option>"; echo "<option value=\"16\">16</option>"; echo "<option value=\"17\">17</option>"; echo "<option value=\"18\">18</option>"; echo "<option value=\"19\">19</option>"; echo "<option value=\"20\">20</option>"; echo "<option value=\"21\">21</option>"; echo "<option value=\"22\">22</option>"; echo "<option value=\"23\">23</option>"; echo "<option value=\"24\">24</option>"; echo "<option value=\"25\">25</option>"; echo "<option value=\"26\">26</option>"; echo "<option value=\"27\">27</option>"; echo "<option value=\"28\">28</option>"; echo "<option value=\"29\">29</option>"; echo "<option value=\"30\">30</option>"; echo "<option value=\"31\">31</option>"; echo "</select>"; echo "</td>\n"; echo "<td width=\"55px\" align=\"left\" valign=\"top\">"; echo "<select name=\"Month\">"; echo "<option value=$Month>$Month</option>"; echo "<option value=\"01\">01</option>"; echo "<option value=\"02\">02</option>"; echo "<option value=\"03\">03</option>"; echo "<option value=\"04\">04</option>"; echo "<option value=\"05\">05</option>"; echo "<option value=\"06\">06</option>"; echo "<option value=\"07\">07</option>"; echo "<option value=\"08\">08</option>"; echo "<option value=\"09\">09</option>"; echo "<option value=\"10\">10</option>"; echo "<option value=\"11\">11</option>"; echo "<option value=\"12\">12</option>"; echo "</select>"; echo "</td>\n"; echo "<td width=\"55px\" align=\"left\" valign=\"top\">"; echo "<select name=\"Year\">"; echo "<option value=$Year>$Year</option>"; echo "<option value=\"07\">07</option>"; echo "<option value=\"08\">08</option>"; echo "<option value=\"09\">09</option>"; echo "<option value=\"10\">10</option>"; echo "<option value=\"11\">11</option>"; echo "<option value=\"12\">12</option>"; echo "<option value=\"13\">13</option>"; echo "<option value=\"14\">14</option>"; echo "<option value=\"15\">15</option>"; echo "<option value=\"16\">16</option>"; echo "<option value=\"17\">17</option>"; echo "<option value=\"18\">18</option>"; echo "<option value=\"19\">19</option>"; echo "<option value=\"20\">20</option>"; echo "</td>\n</tr>\n"; $count++; } ?> Any help would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/73356-solved-displaying-a-html-form-with-php-echo/ Share on other sites More sharing options...
marcus Posted October 15, 2007 Share Posted October 15, 2007 You're crazy for actually echoing echo individual option well, individually. # days for($i=1;$i<=31;$i++){ echo "<option value=\"$i\">$i</option>\n"; } # months { for($j=1;$j<=12;$j++){ echo "<option value=\"$j\">$j</option>\n"; } # years { for($k=2007;$k>=1900;$k--){ echo "<option value=\"$k\">$k</option>\n"; } If anything, you have bad HTML. Quote Link to comment https://forums.phpfreaks.com/topic/73356-solved-displaying-a-html-form-with-php-echo/#findComment-370102 Share on other sites More sharing options...
Barand Posted October 15, 2007 Share Posted October 15, 2007 Works for me in FF and IE6 If you name the selects "day[]", "month[]" and "year[]" they will be posted in arrays for processing <?php foreach ($_POST['day'] as $k=>$day) { $month = $_POST['month'][$k]; $year = $_POST['year'][$k]; // process date } Quote Link to comment https://forums.phpfreaks.com/topic/73356-solved-displaying-a-html-form-with-php-echo/#findComment-370109 Share on other sites More sharing options...
fireice87 Posted October 15, 2007 Author Share Posted October 15, 2007 lol that method does make a lot more sense i couldnt quite get it to work but i get what to do with it now thanks! im afraid i dont understand If you name the selects "day[]", "month[]" and "year[]" they will be posted in arrays for processing <?php foreach ($_POST['day'] as $k=>$day) { $month = $_POST['month'][$k]; $year = $_POST['year'][$k]; // process date } i would normally use the form input to create a value that i use sql to insert into my database Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/73356-solved-displaying-a-html-form-with-php-echo/#findComment-370120 Share on other sites More sharing options...
Barand Posted October 15, 2007 Share Posted October 15, 2007 mgal..'s code is for the options. You need to put in the < select > tags i would normally use the form input to create a value that i use sql to insert into my database To do that you need to get the posted values. If you have several selects, all called month, you'll only post the value from the last one. So you need to post them in an array, or give them all different names (which will be a pain to process). Quote Link to comment https://forums.phpfreaks.com/topic/73356-solved-displaying-a-html-form-with-php-echo/#findComment-370122 Share on other sites More sharing options...
fireice87 Posted October 15, 2007 Author Share Posted October 15, 2007 Hey Ah thankyou i understand now thanks! Sorry i edited my first post just before you responded just to clarify my problem got the first bit of code workin that mgal showed me going to try and use your method now Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/73356-solved-displaying-a-html-form-with-php-echo/#findComment-370127 Share on other sites More sharing options...
Barand Posted October 16, 2007 Share Posted October 16, 2007 @maxudaskin And your point is what, exactly? Quote Link to comment https://forums.phpfreaks.com/topic/73356-solved-displaying-a-html-form-with-php-echo/#findComment-370270 Share on other sites More sharing options...
maxudaskin Posted October 16, 2007 Share Posted October 16, 2007 No point... I just wanted to use that image somewhere and fireice87 was the unlucky recipient. Quote Link to comment https://forums.phpfreaks.com/topic/73356-solved-displaying-a-html-form-with-php-echo/#findComment-370297 Share on other sites More sharing options...
fireice87 Posted October 16, 2007 Author Share Posted October 16, 2007 Thanks for your help got it all working now for any that are wanting some help with a similiar issue heres my finished script The form <form id="addgig" name="addgig" method="post" action="gigstore.php"> <table border="0" cellspacing="1"> <?php while($count < $Howmany) { echo "<tr height=\"22px\">\n"; echo "<td width=\"55px\" align=\"left\" valign=\"top\">"; # days echo "<select name=\"Day[]\">"; for($i=1;$i<=31;$i++){ echo "<option value=\"$i\">$i</option>\n"; } echo "</select>"; echo "</td>"; echo "<td width=\"55px\" align=\"left\" valign=\"top\">"; # months echo "<select name=\"Month[]\">"; for($j=1;$j<=12;$j++){ echo "<option value=\"$j\">$j</option>\n"; } echo "</select>"; echo "</td>"; echo "<td width=\"55px\" align=\"left\" valign=\"top\">"; # years echo "<select name=\"Year[]\">"; for($k=2030;$k>=2007;$k--){ echo "<option value=\"$k\">$k</option>\n"; } echo "</select>"; echo "</td></tr>"; $count++; } ?> <input type="submit" name="Submit" value="Submit" /> </form> to insert into the database <?php $conn = @mysql_connect( "*******", "******, "********") or die ("could not connect to mysql"); #Connect to mysql $rs = @mysql_select_db( "*******", $conn ) or die ("Could not select database"); #select database foreach ($_POST['Day'] as $i=>$Day) { $Month = $_POST['Month'][$i]; $Year = $_POST['Year'][$i]; // process date $Date = $Year."-".$Month."-".$Day; $sql = "INSERT INTO date(`date`)Values (\"$Date\")"; $result= @mysql_query($sql, $conn ) or die(" Could not add style facts"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73356-solved-displaying-a-html-form-with-php-echo/#findComment-370961 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.