I have this website that has an error handling when adding groups, which means if I have already 5 groups the website does not allow to add more. For that to happen I query the database, and with that query result I try to access the length from it.
If that length is <4 I will allow the group to be inserted else I will not allow and only show a message. This can be seen in the code above but for some reason it always allow the insertion into the query.
$con = "put the con here";
$query2 = "SELECT * from title where iduser= {$_SESSION['iduser']}";
$result = mysqli_query($con, $query2) or die (mysql_error());
$num_rows = mysql_num_rows($result);
echo $num_rows; //save the size in $num_rows
if($num_rows < 4){ //Did the condition here
$query="INSERT INTO grouptitle(title,iduser) VALUES ('$variavel',{$_SESSION['id_utilizador']})";
mysqli_query($con, $query) or die (mysql_error());
?>
<script>
alert("Grupo adedd");
self.location="Definitions.php";
<?php }else{ ?>
<script>
alert("Exceded the group limit");
self.location="Definitions.php";
<?php } ?>