homepage Welcome to WebmasterWorld Guest from 54.205.207.53
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Why does my variable only contain the 1st word of a Dropdown Option?
djburg42

10+ Year Member



 
Msg#: 4144 posted 7:10 pm on Jun 18, 2004 (gmt 0)

Hi again all....

I'm back with yet another question. I have a dropdown in my script(The dropdown is populated by a function) that contains 3 words. When I go to insert the selected option into MYSql, for some reason, it only picks up the first word of the 3.

For example, let's say that the drop down listed types of vehicles. In this case, the selected option was "Dodge Grand Caravan". When I echo the variable "vehicle" from the function, all I get in return is "Dodge".

Any suggestions?

Thanks as always!

 

httpwebwitch

WebmasterWorld Administrator httpwebwitch us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4144 posted 7:17 pm on Jun 18, 2004 (gmt 0)

do you have the <option> value in quotes?

jatar_k

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4144 posted 7:18 pm on Jun 18, 2004 (gmt 0)

I would assume it is the space that is tripping it up but a look at a snippet of code might help.

<added>httpwebwitch, quicker and sharper ;)

DigitalSorceress

10+ Year Member



 
Msg#: 4144 posted 7:55 pm on Jun 18, 2004 (gmt 0)

Another approach is to use the "value" value


<select name="foo">
<option value="">PLEASE SELECT SOMETHING</option>
<option value="Foo Bar">Foo Bar</option>
<option value="Foo Bar baz qux etc">Nice Description</option>
</select>

djburg42

10+ Year Member



 
Msg#: 4144 posted 10:21 pm on Jun 18, 2004 (gmt 0)

Thanks for the input all...Sorry about forgetting the code snippets....

Here is the function...

function vehicle($dropdownname,$tablename)
{
db_connect();

$result = mysql_query("Select * from " . $tablename . " Order by Name");

if (!$result)
{
die('Invalid formation of select query in displaydropdownvalues(): ' . mysql_error());
}

echo "<select name=" . $dropdownname . ">";
echo "<option value='' selected></option>";

while ($row = mysql_fetch_array($result, MYSQL_BOTH))
{
echo "<option value=" . $row[1] . ">" . $row[1] . "</option>";
}

echo "</select>";

mysql_free_result($result);

mysql_close();
}

Here is where I call and display it in the table...

<tr>
<td colspan="2"><label for="vehiclename">Vehicle:</label></td>
<td colspan="2"> <name="vehiclename" id="vehiclename" tabindex="3"/><?php vehicle("vehicle", "Name");?></td>
</tr>

Then when I load it into the query for insert into MySQL, I only get the first word. I know it has something to do with the space, but not sure how to correct it....

Timotheos

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4144 posted 10:31 pm on Jun 18, 2004 (gmt 0)

So try what httpwebwitch mentioned.

echo "<option value=\"" . $row[1] . "\">" . $row[1] . "</option>";

djburg42

10+ Year Member



 
Msg#: 4144 posted 3:44 am on Jun 19, 2004 (gmt 0)

Doh!

Thanks httpwebwitch and Timotheos...I missed that....

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved