monkeymade Posted March 12, 2010 Share Posted March 12, 2010 I have a MySQL database set up to hold dates, and a drop down menu to enter a date, when a date is entered, I have it set up to auto select that date on the drop down menu so that you can see what its currently set at. Here is my form code: <select size="1" name="D7"> <option value="01" <?PHP IF ($fuel1 == 01) echo "selected"; ?>>Jan</option> <option value="02" <?PHP IF ($fuel1 == 02) echo "selected"; ?>>Feb</option> <option value="03" <?PHP IF ($fuel1 == 03) echo "selected"; ?>>March</option> <option value="04" <?PHP IF ($fuel1 == 04) echo "selected"; ?>>April</option> <option value="05" <?PHP IF ($fuel1 == 05) echo "selected"; ?>>May</option> <option value="06" <?PHP IF ($fuel1 == 06) echo "selected"; ?>>June</option> <option value="07" <?PHP IF ($fuel1 == 07) echo "selected"; ?>>July</option> <option value="08" <?PHP IF ($fuel1 == 08) echo "selected"; ?>>Aug</option> <option value="09" <?PHP IF ($fuel1 == 09) echo "selected"; ?>>Sept</option> <option value="10" <?PHP IF ($fuel1 == 10) echo "selected"; ?>>Oct</option> <option value="11" <?PHP IF ($fuel1 == 11) echo "selected"; ?>>Nov</option> <option value="12" <?PHP IF ($fuel1 == 12) echo "selected"; ?>>Dec</option> </select> I have the exact same code on the page 5 times... I get the same error in all 5. My MySQL for that date is int 2 unsigned zerofill There error I'm getting is, when I enter a date, it goes in perfectly every time into the MySQL, but the display will not enter "SELECTED" for August or September. For those two months, it displays "Jan" even though the MySQL database still reflects 08 and 09 respectively. I have put in a: <?PHP echo $fuel1; ?> to check the output, and it will display the 08 and 09, but its not working with the IF statement in the form. I've developed a headache looking over this code for so long, and can't find any simple errors. Anyone have any ideas on what I'm doing wrong here? Quote Link to comment Share on other sites More sharing options...
harristweed Posted March 12, 2010 Share Posted March 12, 2010 <option value="08" <?PHP IF ($fuel1 == 08) echo "selected"; ?>>Aug</option> 08 is not a number, it's a string Change to <option value="08" <?PHP IF ($fuel1 == "08") echo "selected"; ?>>Aug</option> and it will work Quote Link to comment Share on other sites More sharing options...
monkeymade Posted March 12, 2010 Author Share Posted March 12, 2010 yup, that did it, thanks a lot! Quote Link to comment 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.