I want to give "awards" to users who complete certain tasks such as getting to level 50. I also want to log everything in case something goes wrong and an admin has to manually insert it.
The php for awards is linked on every page and checks if the user from 'users' table has reached level 50. Once the user is level 50 it will insert username, award, time, reason, and who gave the award into a table called 'awards'.
But if the user is level 50 it will continue inserting into the 'awards' table every time the user reload or goes to a new page. How can i only update if the user doesn't already have the specific award?
if(empty($_SESSION['user'])){
}else{
$member_id = htmlentities($_SESSION['user']['id'], ENT_QUOTES, 'UTF-8');
$db_conn = mysqli_connect("localhost", "root", "password", "a276") or die ("Could not connect to database");
$set_award_query = mysqli_query ($db_conn, "SELECT * FROM users WHERE id='$member_id'");
while($row = mysqli_fetch_array($set_award_query, MYSQLI_ASSOC)){
$member_id = htmlentities($_SESSION['user']['id'], ENT_QUOTES, 'UTF-8');
$member_username = htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8');
$member_level = $row['level'];
}
//Award level50
if($member_level == '50'){
$award_sql = "INSERT INTO `awards` (`awardusername`, `awardby`, `award`, `awardmessage`) VALUES ('$member_username', 'System', 'level50', 'Congratulations on reaching level 50!')";
$db_conn->query($award_sql);
}else{}
Aucun commentaire:
Enregistrer un commentaire