Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

爷,独闯天下 提交于 2019-12-02 04:36:03

This should work:

<select id="cd" name="cd">
    <?php
    while($row=mysql_fetch_array($cdresult)) { 
        echo "<option value=".$row['Poblacion']."></option><br/>"; 
    } 
    mysql_close($link); 
    ?>
</select>

When using array variables inside of strings it's usually better to use the complex syntax:

echo "('<option value='{$row['Poblacion']}'></option >'.'<br />)"; 

Alternatively you can remove the quotes in the array key:

echo "('<option value='$row[Poblacion]'></option >'.'<br />)";

PHP String Variable Parsing

Try changing echo line to this:

echo '<option value="' . $row['Poblacion'] . '"></option >'; 

This line is a mess

echo "('<option value='$row['Poblacion']'></option >'.'<br />)"; 

First off, you can't use other characters around an <option> tag (the <br> tag is meaningless there). And then you leave the text of the tag blank. Finally, you're using double quotes around the whole thing, leaving PHP to try and interpret it. My bet is you're trying to do this instead.

echo '<option value="' . $row['Poblacion'] . '">' . $row['Poblacion'] . '</option>';

This will generate a proper tag AND populate it with the text of your field as well (so users can see what they're selecting). The way you had it, even if it were proper HTML, you'd have a dropdown of nothing but blank entries.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!