-1

I have this website that has an error handling when adding groups, wich 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, can you help me? Thanks in advanced!

$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 } ?>
jose
  • 83
  • 3
  • 11

1 Answers1

0

The 4th line of your code there buddy... try this

$num_rows = mysqli_num_rows($result);
Mohammad
  • 20,339
  • 15
  • 51
  • 79