By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

MSSQL populated dropbox option value truncated

P: 2
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...
$myServer = "...";
$myUser = "...";
$myPass = "...";
$myDB = "...";

$link = mssql_connect( $myServer, $myUser, $myPass );
mssql_select_db( $myDB, $link );
$output = mssql_query("SELECT name FROM staff");
<select name="requestedby" id="requestedby">
<?php while ($row = mssql_fetch_object($output)) { echo "<option value=" . $row->name . ">" . $row->name . "</option>"; } ?>

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

Mar 2 '08 #1
Share this Question
Share on Google+
3 Replies

Expert 2.5K+
P: 4,258
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_object($output)) {
echo "<option value='" . $row->name . "'>" . $row->name . "</option>"; [/php]Ronald
Mar 2 '08 #2

P: 2
Thankyou very much.. works as intended!
Mar 2 '08 #3

Expert 2.5K+
P: 4,258
You are welcome. See you again next time.

Mar 2 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.