Dropdown menu adding wrong value to database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • larsy87
    New Member
    • May 2010
    • 7

    Dropdown menu adding wrong value to database

    Hey guys,

    I was recently given the task of fixing a PHP application page. I don't know PHP, but I do have extensive knowledge of java, js and c/c#/c++.

    That being said, I'm at a loss to fix my problem. The PHP page is a registration form with names, birthdays, etc, all your standard stuff.

    When you fill out the birthday and submit it, the birth day is almost always 1 - sometimes it's 2(very infrequently) and sometimes it will roll back to 31(no provision in code for different lengths of the months).

    I've attached the code for the birth day drop down. I attempted to add the debug lines and neither of them worked for me. The birth month and birth year code all works as it should, only problem being with the day.

    Any insight offered would be greatly appreciated.

    Code:
                    echo "<select size='1' name='child_dob_day[".$child."]'>";
                    for ($day=1;$day<=31;$day++)
                    {
                            echo "<option value='".$day."'";
                            if ($form->values["child_dob_day"][$child] == $day)
                                    echo " selected";
                            echo ">".$day."</option>";
                    }
                    echo "</select>";
  • chathura86
    New Member
    • May 2007
    • 227

    #2
    check your html source if the select box is populated properly

    Regards

    Comment

    • larsy87
      New Member
      • May 2010
      • 7

      #3
      Originally posted by chathura86
      check your html source if the select box is populated properly

      Regards
      I'm not sure what you mean...the days are added to the drop down by the for loop, how else would the box be populated?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        out of interest, what kind of object is $form?

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Look at the source of your page. That is, right-click -> view source. You'll see the rendered HTML. Post it here, and from there we might be able to deduce the problem more efficiently.

          Comment

          • chathura86
            New Member
            • May 2007
            • 227

            #6
            Originally posted by Dormilich
            out of interest, what kind of object is $form?
            it could be a instance of a form object, some (including me) creates form objects
            from a class (custom made), especially when dealing with ajax so we can send the form values as a json object and map with the form object, im not sure may be some frameworks also support this facility.

            Regards

            Comment

            • larsy87
              New Member
              • May 2010
              • 7

              #7
              Code:
              <select size='1' name='child_dob_day[1]'><option value='1'>1</option>
              <option value='2'>2</option>
              <option value='3'>3</option>
              <option value='4'>4</option>
              <option value='5'>5</option>
              <option value='6'>6</option>
              <option value='7'>7</option>
              <option value='8'>8</option>
              <option value='9'>9</option>
              <option value='10'>10</option><option value='11'>11</option><option value='12'>12</option><option value='13'>13</option><option value='14'>14</option><option value='15'>15</option><option value='16'>16</option><option value='17'>17</option><option value='18'>18</option><option value='19'>19</option><option value='20'>20</option><option value='21'>21</option><option value='22'>22</option><option value='23'>23</option><option value='24'>24</option><option value='25'>25</option><option value='26'>26</option><option value='27'>27</option><option value='28'>28</option><option value='29'>29</option><option value='30'>30</option><option value='31'>31</option></select>
              all the values match up, anything else you'd like to see?

              edit: changed code format so it wasn't one huge line...and just a couple lines ;)

              Comment

              Working...