douwei1408 2014-05-24 10:31
浏览 34
已采纳

下拉声明后,PHP变量将不起作用

I've been trying to figure out why my php variables aren't working after the declaration of a dropdown. I've narrowed it down to the dropdown after echoing the variable on all the lines leading up to the declaration, and I found that the variable stops echoing straight after the echo "<select id ='fav' name='fav'>"; Why is this happening? and how can it be fixed?

<?php
$fruit= $_POST['fruit'];
echo $fruit;
echo "<table>";
echo $fruit;
echo "<tr>Favourite Fruit:";
echo $fruit;
echo "<select id ='fav' name='fav'>";
echo $fruit; //this doesn't echo
echo "<option value='Banana'>Banana</option>";
echo "<option value='Strawberry'>Strawberry</option>";
echo "<option value='No Preference'>No Preference</option>";
echo "</select>";
?>
  • 写回答

5条回答 默认 最新

  • doucepei5298 2014-05-24 10:42
    关注

    I think you want this, if you put something inside

    <select></select>
    

    you have to use

    <option></option>
    

    or you can do it like,

      echo $fruit; //this doesn't echo
      echo "<select id ='fav' name='fav'>";
    

    but not like,

     echo "<select id ='fav' name='fav'>";
     echo $fruit; //this doesn't echo
    

    full code will be

    <?php
    $fruit= $_POST['fruit'];
    echo $fruit;
    echo "<table>";
    echo $fruit;
    echo "<tr>Favourite Fruit:";
    echo $fruit;
    echo "<select id ='fav' name='fav'>";
    echo '<option value="';
    echo $fruit . '">';
    echo $fruit;
    echo '</option>';
    echo '</select>';
    .........................
    .........................
    .........................
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计