Jump to content

Recommended Posts

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

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.

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
}

 

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

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).

;D 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");
}

?>



This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.