Permission in PHP

Asked

Viewed 40 times

1

I’m limiting the amount of posts a user posts on 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 logic of registration 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? Thank you

  • 1

    Some mistake, which doesn’t work?

1 answer

0


Missing extract database lines with mysqli_fetch(). mysqli_query() returns a Resource or a false, play 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{
  • Hello @rray, thanks for replying. I made the change in my code and changed the post here on the forum according to what you answered, but it still doesn’t work. Can you review it again? Thank you

  • @Francisvagnerdaluz could detail what does 'not work' mean? the code does not fall into LSE would be this?

  • Yeah. That’s right, don’t fall into Isis

  • @Francisvagnerdaluz before the if do one print_r($numLimite); places the return.

  • appeared this error Warning: mysqli_fetch_assoc() expects Parameter 1 to be mysqli_result, string Given in C: xampp htdocs toqve internal functions.php on line 61 Notice: Undefined variable: tag in C: xampp htdocs toqve internal folder_success.php on line 26

  • the line 61 is Return mysqli_fetch_assoc($query); and the 26 I’ve fixed

  • @Francisvagnerdalight at the time paste the I sent wrong code missed a mysqli_query() before the mysqli_fetch_assoc() I already corrected that in the answers.

  • Thank you so much for your time and your solution! It worked round now.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.