Permission in PHP

1

I am limiting the amount of a user's posts in a service so I created the function:

 function limite($conexao, $id) {

    $query = "select cont_post from usuarios where id={$id}";

    return mysqli_fetch_assoc($query);
  }

and in the registration logic I made the condition:

$numLimite = limite($conexao, $id);

  if($numLimite['cont_post'] >= 5) {

    header("Location: profile.php?=Limite");
  }else{

      $id_empresa = $_POST['id_empresa'];
      $localizacao = $_POST['localizacao'];
      $img = $_FILES['img'];
      $titulo = $_POST['titulo'];
      $texto = $_POST['texto'];
      $telefone = $_POST['telefone'];
      $email = $_POST['email'];
      $site = $_POST['site'];

      if(isset($_FILES['img'])) {
        $nomes = $img['name'];
        $tiposPermitidos = ['jpg', 'jpeg', 'png'];
        $tamanho = $marca['size'];
        $extensao = explode('.', $nomes);
        $extensao = end($extensao);
        $novoNome = rand().'.'.$extensao;

        if(in_array($extensao, $tiposPermitidos)) {
          if($tamanho > 2000000) {
            echo "tamanho exede o limite perfimitido";
          } else {
            $mover = move_uploaded_file($_FILES['img']['tmp_name'], 'envios/'.$novoNome);
            //echo "<img src='envios/$novoNome'>";
          }
        } else {
         echo "tipo de arquivo inválido";
        }
      }

      cadastraFolder($conexao, $id_empresa, $localizacao, $novoNome, $titulo, $texto, $telefone, $email, $site);
      cont_post($conexao, $id, null);

      header("Location: profile.php");
      }

But it's not working, can anyone help me? Thankful

    
asked by anonymous 02.10.2017 / 14:23

1 answer

0

Failed to extract rows from the database with mysqli_fetch() . mysqli_query() returns a resource or a false, playing this in comparison does not give the expected result.

function limite($conexao, $id) {
   $sql = "select cont_post from usuarios where id={$id}";
   $query = mysqli_query($conexao, $sql);
   return mysqli_fetch_assoc($query);
}

Remember to compare the correct field in if.

$numLimite = limite($conexao, $id);
if($numLimite['cont_post'] >= 5) {
   header("Location: profile.php?=Limite");
}else{
    
02.10.2017 / 14:29