Help with tag radio to record in $_SESSION

Asked

Viewed 44 times

0

Hello, using the code below (EDITED) to save the status ($status_prod) of the button (Enabled? Yes or No), and also save the target address ($link_prod) of the button. But he’s only recording the YES option now, and I’m not finding out how to get him to record the selected option regardless of which.

    <?php
    @session_start(); // Inicia a session.

    if(!isset($_SESSION['hab_prod'])){ 
    // Se a Session não existir eu crio...
    $status_prod = 'Sim'; // Carrega esse conteúdo
    $link_prod = '<li><a href="'.$end.'prod_index.php" class="nav1">'.$bot_prod.'</a></li><li class="divider"></li>'; // Carrega esse conteúdo

    //Armazena os dados na sessão que pode ser bidimensiona(array)
    $_SESSION['hab_prod']['status_prod']=$status_prod;
    $_SESSION['hab_prod']['link_prod']=$link_prod;

    }else if(isset($_SESSION['hab_prod'])){
     // Se existir sessão, eu crio aqui
    $status_prod = $_SESSION['hab_prod']["status_prod"];
    $link_prod = $_SESSION['hab_prod']["link_prod"];
    }
    ?>

    <?php
//pega o valor do botao
        if(isset($_POST['status_prod'])){ // só entra aqui, se gale_status tiver sido postado
                $link_prod = null;
                $status_prod = 'Não';

// se a pessoa marcar a opção sim:
        if($_POST['status_prod'] == "1") {
                $link_prod = '<li><a href="'.$end.'prod_index.php" class="nav1">'.$bot_prod.'</a></li><li class="divider"></li>';
                $status_prod = 'Sim';

        //}else if(isset($_POST['status_prod'])){ // Com essa linha funciona a opção NÃO
        if(!empty($status_prod)) {              // Com essa linha funciona a opção SIM

// Se existir sessão, eu crio aqui
        $_SESSION['hab_prod']['status_prod']=$status_prod;
        $_SESSION['hab_prod']['link_prod']=$link_prod;

        echo "<meta http-equiv='refresh' content='0; URL= menu_halitar_link.php'>
        <script language='javascript'>
        window.alert('Dados atualizados com sucesso!');
        </script>";
        }}} // Retirar uma Chave se for usar a opção NÃO
    ?>

        <form method="post">
            <label>Habilitar o Link <?php echo $bot_prod ?>?</label><br><br>
            <input type='radio' name='status_prod' value='1' checked="checked"/><label>Sim</label>
            <input type='radio' name='status_prod' value='0'><label>Não</label>
            <input type="submit" value="Atualizar">
        </form>

I am posting the addresses so that friends can check the problem that is occurring.

Address of the panel where you changed the status of the button: http://www.simuleseusite.com/admin/

Access with (Login - user) and (Password - 123)

Log in (menu/enable button) Do the test by switching from Yes to No, and try to unlock it, and you will see that you are not recording the Yes option.

Button Enabling Result Address: http://www.simuleseusite.com/

If friends can help me to find out where I’m going wrong I’d be very grateful.

Fight to all, and big hug.

  • Test check with String and not Number. That is if($_POST['status_prod'] == "1" and not only == 1

  • On the page always comes back with the yes. Your input is with the yes checked <input type='radio' name='status_prod' value='1' checked="checked"/>, even if you update in BD HTML will always display yes.

  • Sergio did what you. suggested, but also did not work, IE did not take effect the change of == 1 for == "1". And Papa, I’m not referring to the radio buttons, but to the result you’ll get on the left side in the question whether the "Link Products this enabled?" it starts as YES, you change to Not, but cannot return to the Yes selecting the button and updating it. There is the problem, in the update when selected the button Yes. But thanks for the tips, but I’m still waiting for tips to solve the problem, and if I succeed, put the solution.

  • Doing some research in the network I found and implanted this line if(!empty($status_prod)) { replacing this }else if(isset($_POST['status_prod'])){, that made the option of YES, but for some reason the option works NAY. So any idea how to make it work with two options? But we have to remove one of the three keys at the end of the code, when using this option }else if(isset($_POST['status_prod'])){. With that line }else if(isset($_POST['status_prod'])){, works the option No and with this if(!empty($status_prod)) { option YES, and there?

  • I edited the code by inserting the line that makes the YES work.

  • Where is the code that this section "Link Products is enabled?" ?

Show 1 more comment

1 answer

0

Problem solved with the help of friend Miguel, as POST

Below working code:

<?php
if(isset($_POST['status_prod'])) {

if(isset($_POST['status_prod']) && ($_POST['status_prod']) == 0) { // Desabilita o Botão.
    $link_prod = null;
    $status_prod = 'Não';
}else{
    $_POST['status_prod'] == 1; // Habilita o Botão com o Link de destino.
        $link_prod = '<li><a href="'.$end.'prod_index.php" class="nav1">'.$bot_prod.'</a></li><li class="divider"></li>';
        $status_prod = 'Sim';
        }
        $_SESSION['hab_prod']['status_prod'] = $status_prod;
        $_SESSION['hab_prod']['link_prod'] = $link_prod;

        echo "<meta http-equiv='refresh' content='0; URL= menu_halitar_link.php'>
        <script language='javascript'>
        window.alert('Dados atualizados com sucesso!');
        </script>";
        }
?>
        <form method="post">
            <label>Habilitar o Link <?php echo $bot_prod ?>?</label><br><br>
            <input type='radio' name='status_prod' value='1' checked="checked"/><label>Sim</label>
            <input type='radio' name='status_prod' value='0'/><label>Não</label>
            <input type="submit" value="Atualizar">
        </form>

Hugs to all.

Browser other questions tagged

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