简体   繁体   中英

PHP Variable being cut off in <option>

while ($row = sqlite_fetch_array($result))
{
$category = $row[0];
    echo "<option value=". $category .">". $category ."</option>\n";

} 

Ok so basically, $category is a string like : Java Network Programming, and in the 'VALUE' part it only passes through "Java", where as in the second part, it passes through the whole string?

Any reason why, as this is kind of crucial. I have tried :

<option value=$category>

And still no luck, I just don't see why it works with one variable and not the other?

引用你的属性,并通过htmlentities($value, ENT_QUOTES)对它们进行编码,以防它们包含内部引号。

echo "<option value='". htmlentities($category, ENT_QUOTES) ."'>". $category ."</option>\n";

It looks like a missing quotes issue to me:

while ($row = sqlite_fetch_array($result))
{
    $category = $row[0];
    echo '<option value="'. $category .'">'. $category ."</option>\n";
} 

您需要引用HTML属性。

echo "<option value='". $category ."'>". $category ."</option>\n";

I'm not sure why this is happening bu if you try this it should work

echo "<option value='". $category ."'>". $category ."</option>\n";

Just enclose the $category in '' as I've done.

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM