MSSQL populated dropbox option value truncated

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • grantf3
    New Member
    • Mar 2008
    • 2

    MSSQL populated dropbox option value truncated

    Hi all, I am currently trying to populate a dropbox with values from a MSSQL DB. The values that are being brought back from the table are two words - peoples full names, eg 'John Smith' (in the one field). My problem is that using the code below, only the person's first name is being posted to the subsequent page and the surname is lost. Does anyone know what is wrong with this code? I'm pretty sure it has somethin to do with the fact there is a space in the field value...
    [php]
    <?php
    $myServer = "...";
    $myUser = "...";
    $myPass = "...";
    $myDB = "...";

    $link = mssql_connect( $myServer, $myUser, $myPass );
    mssql_select_db ( $myDB, $link );
    $output = mssql_query("SE LECT name FROM staff");
    ?>
    <select name="requested by" id="requestedby ">
    <?php while ($row = mssql_fetch_obj ect($output)) { echo "<option value=" . $row->name . ">" . $row->name . "</option>"; } ?>
    </select>[/php]

    Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

    moderator
    Last edited by ronverdonk; Mar 2 '08, 11:16 AM. Reason: code tags
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Welcome to The Scripts!

    Since the value contains blanks, these will be stripped. Always enclose a value field within quotation marks. For you this means:[php]while ($row = mssql_fetch_obj ect($output)) {
    echo "<option value='" . $row->name . "'>" . $row->name . "</option>"; [/php]Ronald

    Comment

    • grantf3
      New Member
      • Mar 2008
      • 2

      #3
      Thankyou very much.. works as intended!

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        You are welcome. See you again next time.

        Ronald

        Comment

        Working...