i have a button, i want it every time i click the button it'll subtract from my credit on database (MySQL). i tried everything that already answered on another question but still unable to solved my problem.
here's my code
<input type="submit" name="submit" value="Check" class="button_x" style="width:100px" >
<?php
if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['submit']))
{
func();
}
function func()
{
$query = "UPDATE users SET user_credit = user_credit - 2";
$result = mysqli_query($conn, $query);
}
?>
if im not using the if function, it work! but it would subtract the credit when i click the sub menu as well. or should i add 'where' at my query?
thank you.