-1

I have to make an if statement to place a form in my page if the user is an admin, but I'm having trouble with the syntax. Right now it is like this:

    if($_SESSION['tipo'] == "admin")
                {
                    echo '<form method=\'POST\' action=\'adicionaproduto.php\'>
                        <input type=\"submit\" value=\"Adicionar Produto\" name=\"adicionaproduto\">
                    </form>'
                }

It is not working and I think it's a mater of using "" or '.

Marc B
  • 348,685
  • 41
  • 398
  • 480
Hugo Torres
  • 158
  • 2
  • 10
  • 1
    Don't escape the double quotes. You only escape the quotes being used by PHP for encapsulating the string's data. Oh and you missed a closing `;` after the echo.. – chris85 Nov 02 '15 at 16:12
  • 1
    had you bothered checking for errors with error reporting, it would have told you about the syntax error `'` see what's missing? Visit this http://php.net/manual/en/function.error-reporting.php and apply it to your code and make sure you started the session. – Funk Forty Niner Nov 02 '15 at 16:12

2 Answers2

0

Try This:

if($_SESSION['tipo'] == "admin")
             { ?>
                  <form method='POST' action='adicionaproduto.php'>
                  <input type="submit" value="Adicionar Produto" name="adicionaproduto">
                   </form>
           <?php  } ?>
Maha Dev
  • 3,709
  • 1
  • 28
  • 49
0
if($_SESSION['tipo'] == "admin"){
  echo '
        <form method="POST" action="adicionaproduto.php">
         <input type="submit" value="Adicionar Produto" name="adicionaproduto">
        </form>';
}

This should get you started i echoed using single quotes and the used double quotes all through afterwards in order to avoid escaping strings. This is good practise for echoing html in php

Mueyiwa Moses Ikomi
  • 1,049
  • 2
  • 12
  • 26