Where is the mistake?

Asked

Viewed 70 times

-7

     while($row = mysql_fetch_assoc($result))
{
 if($row['level'] = '0')
 {
 echo("Fundador '); //pode fazer tudo
 }

  if($row['level'] = '1')
 {
 echo('Admin'); //  nao pode adicionar nem remover e/ou edit users
 }

      if($row['level'] = '2')
     {
        echo('Moderador de canais'); //n tem acesso a pagina de jogos e filmes
     }

          if($row['level'] = '3')
     {
        echo('Moderador de jogos'); // n tem acesso a pagina canais e filmes
     }
          if($row['level'] = '4')
     {
        echo('Moderador de filmes'); //n tem acesso a pagina de canais e jogos.
     }
 else
 {
 echo("Membro'); //sem permissoes p ver as paginas
 }
}
  • 4

    Here’s the bug apparently, you open a double quote and close a single in that line: echo("Fundador '); and in that other echo("Membro');. To avoid this type of error use an IDE or text editor with Highlight, you can see a list here in addition to other php tips.

  • 3

    Hi Rodrigo, welcome to the site. Maybe you are surprised by the negative repercussion of your question. Unfortunately, I don’t have the mental powers to tell you the reason for every vote against. But I can tell you that the lack of indentation of your code is a possible motive. Correctly indenting and using tools such as a color-coded editor are key to realizing this type of error, not only for beginners, but for any programmer. Those who denied the question must have considered that you did not make the least effort alone before asking others.

  • 2

    When posting a question here, it is also important to show the error message that appears to you. This makes life much easier for those who try to help you. If you don’t post the error message, those who want to help will have more work. The lack of the message, added to its minimum title, may be another reason for votes against. Try to be more specific in the title. Think that your question may help other people besides you if it is well written. Finally, it is worth a visit to our [tour] and to [help]. There you will better understand the differences of this site to the traditional forums.

  • And don’t forget to visit the Manual on how not to ask questions!

2 answers

3


There is more than one error, the way it is whenever a record is not level 4 it will fall on Else.

There is also an error in closing quotation marks on two lines (5 and 30)

The correct code would be:

while ($row = mysql_fetch_assoc($result)) {
    if ($row['level'] = '0') {
        echo("Fundador"); //pode fazer tudo
    }
    else if ($row['level'] = '1') {
        echo('Admin'); //  nao pode adicionar nem remover e/ou edit users
    }
    else if ($row['level'] = '2') {
        echo('Moderador de canais'); //n tem acesso a pagina de jogos e filmes
    }
    else if ($row['level'] = '3') {
        echo('Moderador de jogos'); // n tem acesso a pagina canais e filmes
    }
    else if ($row['level'] = '4') {
        echo('Moderador de filmes'); //n tem acesso a pagina de canais e jogos.
    } 
    else {
        echo("Membro"); //sem permissoes p ver as paginas
    }
}

1

You’re on line 5:

echo("Fundador '); //pode fazer tudo

You’re opening with double quotes and closing with single quotes. Swap ' for " and it will work again, like this:

echo("Fundador"); //pode fazer tudo

Browser other questions tagged

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