Doubt in IF - PHP

1

I'm having a question in the condition I'm trying to put on my system. If the% of the owner of the ad is equal to that of the session, a "accept negotiation" button will appear, otherwise the "Product on the go" button will appear. When testing, only the "Accept negotiation" button will appear.

Follow the code:

<?php
$id_usuario_anuncio = $_GET["ID_usuario"];
$id_usuario_sessao = $_SESSION["id"];
if($id_usuario_anuncio == $id_usuario_sessao)
{
   echo '<form method="post" action="">
   <input type="hidden" name="ATIVAR/EXCLUIR" value="<?php echo $_GET["ID"]; ?>">
   <div class="panel-footer">
   <button type="submit" name="ativar" id="ativar" value="ATIVAR"class="botao_cardapio">Aceitar negocição</button> 
   </div>
   </form>';
}
else
{
   echo '<form method="post" action="">
   <input type="hidden" name="ATIVAR/EXCLUIR" value="<?php echo $_GET["ID"]; ?>">
   <div class="panel-footer">
   <button type="submit" name="excluir" id="excluir" value="EXCLUIR"class="botao_cardapio">Produto a caminho</button> 
   </div>
   </form>';
}
?>
    
asked by anonymous 05.11.2017 / 00:43

1 answer

1

Your problem is with the syntax that is totally incorrect. See examples on line 7 and line 16. You have opened PHP tag inside a PHP tag. So the resolution is simple:

<?php
$id_usuario_anuncio = $_GET["ID_usuario"];
$id_usuario_sessao = $_SESSION["id"];


if($id_usuario_anuncio == $id_usuario_sessao)
    {
    echo '<form method="post" action="">
    <input type="hidden" name="ATIVAR/EXCLUIR" value="'.$_GET["ID"].'">
    <div class="panel-footer">
    <button type="submit" name="ativar" id="ativar" value="ATIVAR" class="botao_cardapio">Aceitar negocição</button> 
    </div>
    </form>';
    }
else
    {
    echo '<form method="post" action="">
    <input type="hidden" name="ATIVAR/EXCLUIR" value="'.$_GET["ID"].'>
    <div class="panel-footer">
    <button type="submit" name="excluir" id="excluir" value="EXCLUIR" class="botao_cardapio">Produto a caminho</button> 
    </div>
    </form>';
    }
?>

But if you will, I've created a somewhat simpler system so you do not double the size of your file (which implies bandwidth when hosting):

<?php
$ua = $_GET["ID_usuario"];
$us = $_SESSION["id"];

    if ($ua == $us) {
        $text  = "Aceitar negociação";
        $name_id = "ativar";
    } else {
        $text  = "Produto a caminho";
        $name_id = "excluir";
    }
    $value = strtoupper($name_id); // retorna "ACEITAR"

?>

<form method="post" action="">
    <input type="hidden" name="ATIVAR/EXCLUIR" value="<?php echo $_GET['ID'] ?>">
    <div class="panel-footer">
    <button type="submit" name="<?php echo $name_id ?>" id="<?php echo $name_id ?>" value="<?php echo $value ?>" class="botao_cardapio"><?php echo $text ?></button> 
    </div>
</form>
    
05.11.2017 / 01:44