So I am trying to make a select element update a MYSQL record every time the selection is changed. But the only way I was successfully able to trigger the PHP code is through an input button and not what is shown below. I need to be able to trigger the PHP code with the invisible input submit.
The whole point is to update PHP records through the select element and no button.
<form id="signin-form_id" class="panel" method="POST" style="margin-bottom: 0px;">
<div class="input-group">
<span class="input-group-addon">
Coin
</span>
<select class="form-control" name="cointype" onchange="this.form.submit()">
<option value="0" selected>Bitcoin</option>
<option value="1">Litecoin</option>
</select>
</div>
<noscript><input type="submit" name="ReferralCoin"></noscript>
</form>
And the submit button is suppose to trigger a POST event in PHP seen here: Do not comment about MYSQL injection vulnerabilities.
<?php
if (isset($_POST['ReferralCoin']))
{
$cointype = $_POST['cointype'];
if($cointype == "0")
{
$odb->exec("UPDATE users SET `coin` = '$cointype' WHERE `ID` = '$userid'");
}
elseif($cointype == "1")
{
$odb->exec("UPDATE users SET `coin` = '$cointype' WHERE `ID` = '$userid'");
}
}
?>
The problem is if I was to use an input button it works fine and triggers the php POST code, but when using the invisible input submit it does not trigger the PHP POST code. If anyone can help me find my mistake, much is appreciated!