使用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.

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>';

So, you would make your form method "POST' and the action the url of the PHP script.

Then, in the PHP script you would use $_POST variable which would contain all of the info that was submitted in that form. See here:

http://php.net/manual/en/reserved.variables.post.php

There is a similar variable for get requests. For hte difference in get and post methods see here: http://www.w3schools.com/tags/ref_httpmethods.asp

This is an example script you can use:

php file:

<?php
    if(isset($_POST['submit'];)) {
        session_start();
        $text = $_POST['Text'];
        echo "$text";}else {echo 'Could not load text!';}
?>
<form method="POST">
<input name="Text" type="text">
<input type="submit" name="submit">
</form