I am making a ranking system which checks if the user's XP meets a certain level then updates the database with their new rank. Here is my code currently.
<?php
session_start();
$servername = "localhost";
$username = "USERNAME";
$password = "PASSWORD";
$dbname = "DB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$id=$_SESSION['user']['id'];
$sl = "SELECT * FROM users WHERE id='$id'";
$reult = $conn->query($sl);
while($ro = $reult->fetch_assoc()) {
if($ro['xp']>2000){
$sql = "UPDATE users SET rank='2' WHERE id='$id'";
if ($conn->query($sql) === TRUE) {
echo"Success";
}
} //ENDS THE IF
elseif($ro['xp']>"5000"){
$sel = "UPDATE users SET rank='3' WHERE id='$id'";
if ($conn->query($sel) === TRUE) {
echo"Success";
}
}//ENDS ELSEIF
}//WHILE LOOP ENDS
$conn->close();
?>
But PHP wont allow the elseif's
to keep running if the first if
is met. Is ther a better way to do this in PHP?