I have a section of code where the user completes an input form in HTML.
On post I validate their $_POST entry $userAmt
against their points available $points
in the database and then I proceed.
I've noticed that some users are able to circumvent my initial check and enter more points than are available in the database only as long as it's within the range of the second validation 1-20
. So some part of the validation is working, but I'm guessing they are able to use a break point and edit the post variables after my initial validation? Here's a snippet of the code.
$query = mysqli_query($conn, "SELECT * FROM users WHERE id = '$id'");
$queryA = mysqli_fetch_assoc($query);
$points = $queryA['points']; //user points available
if(isset($_POST['submit'])){
$userAmt = $_POST['userInput']; //users input
$userAmt = mysqli_real_escape_string($conn, $userAmt);
$prize = $userAmt * 2;
if($userAmt > $points ){ //<- attackers are circumventing
$message = "You do not have enough points";
} else if ($userAmt < 1 || $userAmt > 20){ //<-attackers are not circumventing
$message = "Must be between 1 and 20";
} else {
// determine outcome and update DB
// if user wins
mysqli_query($conn, "UPDATE users SET points = points + '$prize' WHERE id = '$id'");
}
}
Maybe I shouldn't be doing else if's and instead case switch?