duanmoen784988 2015-03-16 04:51
浏览 138
已采纳

尝试从PHP中的选择下拉菜单中回显值

I am in school for web development, so I clearly don't know a lot yet. I am trying to grab a value from a select, and output it in a paragraph. I know it's about the Browns, but everything else works, but I cannot seem to find anything on StackOverflow, or Google on how to grab the value that works. I get the following error:

Notice: Undefined variable: draft in C:\wamp\www\lab 5\process.php on line 42

This error is in my paragraph, which makes me think I am grabbing the value, but it isn't outputting correctly? I am using a variable to show where I want to output that value in the paragraph.

This is my HTML:

 <li><select id="uDraft"
            <select>
            <option value="Draft Offense">Draft Offense</value>
            <option value="Draft Defense">Draft Defense</value>
            <option value="Trade them, we can't pick good anyways">Trade them,  we can't pick good anyways</value>

        </select></li>

This is my process.php code:

if(isset($_GET["uDraft"])){
$draft= $_GET["uDraft"];
}
echo "I want to output **$draft var** as the value they choose so it shows                       the choice in a paragraph that is pre-written"; 

All of my other text boxes work, I just cannot seem to get the value from the select, so that I can show what it says in the text, into the paragraph. I also had a select for wins, but gave up when I couldn't figure out how to grab the value. I know I can use radio buttons, but I am trying to learn how to grab the value from the drop down. Any help would be greatly appreciated.

  • 写回答

2条回答 默认 最新

  • doukezi4606 2015-03-16 04:57
    关注

    You need to give your dropdown a name:

    HTML:

    <li>
       <select name="uDraft">
          <option value="Draft Offense">Draft Offense</option>
          <option value="Draft Defense">Draft Defense</option>
          <option value="Trade them, we can't pick good anyways">Trade them,  we can't pick good anyways</option>
    
       </select>
    </li>
    

    PHP:

    if(isset($_GET["uDraft"])){
        $draft= $_GET["uDraft"];
        echo $draft;
    }  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部