Ad

Get Value From HTML Input Form With PHP

- 1 answer

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.

Ad

Answer

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>';
Ad
source: stackoverflow.com
Ad