Data truncated on passing a value from a drop down menu.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • empk
    New Member
    • Feb 2010
    • 6

    Data truncated on passing a value from a drop down menu.

    I've a table where in a column is defined as nam char(75) default null. Let us say the name is 'American Bush'. The name is picked up from the table and displayed correctly in the dropdown menu in the form. But when it is passed on to another mysql table, the data is truncated as 'American' only. The second part of the string 'Bush' is truncated. If the two words of the string is concatenated with either an underscore or a full-stop or a dash, to make it seem as a single word, it is picked up fine. Why not space between two words. Beats me. I've seen replies on this forum stating that this is an html problem and the value is to be within quotes for it to be displayed properly. My problem is not with display on my browser but the value picked up for passing on to another table which is truncated. Any ideas anyone?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    my guess is, that your insert SQL may be causing that, but currently my orb is out of order.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hey.

      Could you show us the HTML used for the drop-down? (After it is processed by PHP. From your browser.)

      The most likely explanation for this is that you left out the quotes for the value attribute.
      [code=html]// Passes only: "American" to the receiving page, even
      // tho it displays: "American Bush" in the browser.
      <option value=American Bush>American Bush</option>

      // Passes and displays: "American Bush"
      <option value="American Bush">American Bush</option>[/code]
      If you leave them out, the HTML parser takes "American" as the vale of the value attribute, and assumes "Bush" is the name of another attribute. (How is the HTML parses supposed to know the space in the text is supposed to be a part of the text?)
      Last edited by Atli; Feb 21 '10, 12:50 PM. Reason: Updated a bit.

      Comment

      • itsloop
        New Member
        • May 2009
        • 18

        #4
        in simple word whenever you adding any option tag like

        Code:
        <option value=hello world>Hello world</option>
        you should add double quotes whenever you providing any value

        Example
        Code:
        <option value =hello world>hello world</option> <!--Wrong Way-->
        <option value ="hello world">hello world</option> <!--Correct Way-->

        Comment

        • empk
          New Member
          • Feb 2010
          • 6

          #5
          Dear Atli,
          the code used by me for display of the drop down is as under.

          Code:
          $qry2=mysql_query("select * from BORW_MAST order by nam");
          
          <font color=brown>Name :
          <select name=nam>
          
          <?php
          print "<option value=''></option>";     
              while($row=mysql_fetch_row($qry2))
              {print "<option value=$row[1]>$row[1]</option>";
              }
          ?>
          </select>
          Am actually picking up the value of the name from a table which has the structure as nam varchar(75) default null. The display in the drop-down appears in full i.e., "American Bush". But the value passed from this drop-down's display is not in full when inserted into another table, it appears as "American" with "Bush" truncated. Hope I made myself clear.
          Last edited by Dormilich; Feb 22 '10, 05:18 AM. Reason: Please use [code] tags when posting code

          Comment

          • johny10151981
            Top Contributor
            • Jan 2010
            • 1059

            #6
            Code:
               1. $qry2=mysql_query("select * from BORW_MAST order by nam");
               2.  
               3. <font color=brown>Name :
               4. <select name=nam>
               5.  
               6. <?php
               7. print "<option value=''></option>";     
               8.     while($row=mysql_fetch_row($qry2))
               9.     {print "<option value=$row[1]>$row[1]</option>";
              10.     }
              11. ?>
              12. </select>
            still you have the same problem which is described by atli

            Comment

            • Atli
              Recognized Expert Expert
              • Nov 2006
              • 5062

              #7
              Please read the previous posts. Both me and itsloop told you exactly what is wrong and how to fix it.

              Comment

              • empk
                New Member
                • Feb 2010
                • 6

                #8
                Thanks one and all for your help.

                Comment

                • empk
                  New Member
                  • Feb 2010
                  • 6

                  #9
                  Dear johny10151981,
                  Your solution was the best and it went through as a whistle. I substituted the line no. 9 with *print "<option value=\"$row[1]\">$row[1]</option>";*
                  Thanks a lot mate.

                  Comment

                  Working...