Skip to content Skip to sidebar Skip to footer

How To Get Php To Read In A String Of Words From A Dropdown Box?

thank you all so very much for helping. It's seemingly such an easy task, and I feel I just hit a brick wall and not knowing how to fix it. I'll try to explain what I am doing a bi

Solution 1:

Hopefully, your MYSQL database has a primary key? If it does, set the value of each <option> to the primary key of the item.

For example:

SQL

id  desc
1   "dressmaker thing with mannequin"
2   "dressmaker thing no mannequin"

Form PHP

echo"<option value='".$query['id']."'>".$query['desc']."</option>";

When form is submitted, re-query the database for the desired description. You'll be doing this re-query anyway to retrieve prices and such, yes?

The reason this is happening is that spaces are discouraged in HTML attributes. You shouldn't have an attribute like value='this attribute is spaced'.

Solution 2:

If you really have what you posted as the code, then you're missing quotes around the value:

<option value=" . $row['style'] . ">

This would produce:

<optionvalue=dressmakermannequinsize12>

That's not valid html, and the parser is going to think only the first word is the value. You need to put your value in quotes:

<option value='" . $row['style'] . "'>GOOD: <option value='dressmaker mannequin size 12'>

Now your value will be everything inside the quotes. Be careful, though, because if you have quotes inside the $row['style'] value, then it will prematurely escape your value.

BAD: <option value='this won't work because of the apostrophe in won't'>

Notice how in this forum the coloring of the code text works to show what the values are, and explains why you keep getting just 'dressmaker'.

Post a Comment for "How To Get Php To Read In A String Of Words From A Dropdown Box?"