dongzhuo5185 2016-01-08 16:27
浏览 26
已采纳

使用PHP从HTML输入表单获取价值[关闭]

I am wanting to literally take the HTML form input with the ID "bet" and after the value has been entered and submitted; get the exact input for example: '100' may be entered, as I am wanting to perform an if statement to check that the value submitted isn't less than 0 for obvious reasons so then I can stop the webpage proceeding to perform the bet, and make the user instead enter a valid amount.

The code that I am having an issue with is below, upon loading the page I am getting the error: Notice: Undefined index: bet

<form action="duel.php" name="duel" id="duel">
<input type="text" id="betamount" name="betamount">
<?php
$data = $_GET['betamount'];
echo $data;
?>
</form>

I am fairly new to programming in PHP, so any help would be greatly appreciated.

  • 写回答

3条回答 默认 最新

  • dousong5161 2016-01-08 16:44
    关注

    You need to assign a name to the input element. In your situation, you could use the same name as your id:

    <input id='bet' name='bet' type='text' value='100' />
    

    To get the specific data for the 'bet' input field use:

    echo $_POST['bet'];
    

    On your server to view all of the post data use the code:

    // Wrapping the output in the pre block makes the POST data easier to read
    echo '<pre>';
    print_r($_POST);
    echo '</pre>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

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

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

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

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

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

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

客服 返回
顶部