doudilin1225 2014-02-04 14:50
浏览 20

PHP-Strings包含空间输出

I have 2 files. "index.php" and "output.php". Inside index.php I have a dropdown-list containing all Italian cities that was obtained from mysql table. Scope of my test is to select a city from dropdown-list and send value to output.php that print the value.

this is my code:

-index.php:

    <form action="output.php" method="post">
<div align="center">
<?php
echo "Questa è una prova";

// Open db connection
$con = mysqli_connect ( "127.0.0.1", "root", "", "test" );

// Check connection
if (mysqli_connect_errno ( $con )) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error ();
}

echo "</br>";
echo "</br>";
echo "</br>";

//Query principale
$result = mysqli_query ( $con, "SELECT * FROM it_cities" );
?>

<select name="fcity">
<?php 
while($row = mysqli_fetch_array($result))
{
    echo '<option value='  . $row['comuni'] .  '>' . $row['comuni'] . '</option>';
    echo "<br>";
}
?>
</select>
</br>
<input type="submit" value="Invia">
</div>
</form>

-output.php:

   <?php

$city= $_REQUEST ['fcity'] ;

echo "$city" ;

?>

My problem is with strings containing space (example "Abano Terme", only "Abano" is printed on the screen).

Thanks

  • 写回答

1条回答 默认 最新

  • douchen7366 2014-02-04 14:54
    关注

    This is because you're missing quotes around your option elements.

    echo '<option value='  . $row['comuni'] .  '>' . $row['comuni'] . '</option>';
                        ^----------------------^
    

    Change it to

    echo '<option value="'  . $row['comuni'] .  '">' . $row['comuni'] . '</option>';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入