This question already has an answer here:
I'm writing a PHP script that take in a set of inputs and puts it into a mySQL database. Currently, it just takes a set of inputs and enters it into a MYSQL database. Here's my code below.
<?php
// Create connection
$con=mysqli_connect("localhost","username","password","data");
$username = $_POST['a'];
$report = $_POST['b'];
// This SQL statement inserts data into table 'Lion_Datahere
$sql = "INSERT INTO `User_Reports` (`user_name`, `report`) VALUES ('$username', '$report')";
if ($con->query($sql) === TRUE) {
echo "New record created successfully";
}
// Close connections
mysqli_close($con);
?>
I want to modify this script so that it only allows the user to submit a report up to three times. How do I change this so that before inserting it checks if the variable user_id occurs more than three times in the column user_name, and discards it if the user has already hit the limit?
</div>