dongzhuo5185 2016-01-09 00: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-09 00: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条)

报告相同问题?

悬赏问题

  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?