Help to record two values in $_SESSION using a single radio form

Asked

Viewed 67 times

0

I have this code below working perfect for recording in BD:

            <?php
        include '../conexao.php';

        $codigo = $_POST['codigo'];
        $servico = $_POST['servico'];
        $servico_status = $_POST['servico_status'];

        $query = mysql_query("SELECT * FROM menu");
        $res = mysql_fetch_array($query);

        // checar se foi postado algo:
        if (isset($_POST['servico_status'])) { // só entra aqui, se gale_status tiver sido postado
            $link = null;
            $status = 'Não';
            // se a pessoa marcar a opção sim:
            if ($_POST['servico_status'] == 1) {
                $status = 'Sim';
                $link = '<li><a href="'.$res['dominio'].'serv_index.php" class="nav1">'.$res['bot_serv'].'</a></li><li class="divider"></li>';
            }
            // acho que tá faltando definir uma id em seu update.
            $update = mysql_query("UPDATE menu SET servico = '$link', servico_status = '$status'");
            if ($update == '') {
                echo "<script language='javascript'>window.alert('Erro ao Habilitar Link ".$res['bot_serv']."!');</script>";
            } else {
                echo "<meta http-equiv='refresh' content='0; URL= menu_halitar_link.php'>
                          <script language='javascript'>window.alert('Link ".$res['bot_serv']." Habilitado com sucesso!');</script>";
            }
        }

        //  só use: enctype="multipart/form-data" quando o formulário fizer upload de algum arquivo.
        ?>
        <form method="post">
            <label>Habilitar o Link <?php echo $res['bot_serv'];?>?</label><br><br>
            <input type='radio' name='servico_status' value='1' checked="checked"/><label>Sim</label>
            <input type="radio" name="servico_status" value='0'><label>Não</label>
            <input type="submit" value="Atualizar">
        </form>

But I am trying to create a simulator and I need to adapt this code above, so that it records in two different $_SESSION, in $_SESSION['hab_prod']['status_prod'] and in $_SESSION['hab_prod']['link_prod'].

Edited Code:

I changed the code and only managed to achieve my goal which is to save the na $_SESSION['hab_prod'] the $status_prod Enabled (Yes or No) and $link_prod (Button Address), including another Radio, and in PHP separating the code individually.

On the Page I will have to be selecting both radio for it to work.

I ask friends if there is another way where I can select a single radio to record the two value options.

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

    //pega o valor do botao
    $botao=$_POST['atualizar'];
    //verifica se o botao foi clicado
    if($botao=="Atualizar"){
       $status_prod = $_POST['status_prod'];       
    if(isset($status_prod)) {
        $_SESSION['hab_prod']["status_prod"] = $status_prod;
    }}
    //pega o valor do botao
    $botao=$_POST['atualizar'];
    //verifica se o botao foi clicado
    if($botao=="Atualizar"){
       $link_prod = $_POST['link_prod'];
    if(isset($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 style="margin-left:-66px;" type='radio' name='link_prod'
            value='<li><a href="<?php echo $end ?>prod_index.php" class="nav1"><?php echo $bot_prod ?></a></li><li class="divider"></li>'
            checked="checked"/><label>Sim</label>
            <input type="radio" name="link_prod" value=''><label>Não</label><br />
            <input type='radio' name='status_prod' value='Sim' checked="checked"/><label>Sim</label>
            <input type="radio" name="status_prod" value='Não'><label>Não</label>
            <input type="submit" name="atualizar" value="Atualizar">
        </form>

If anyone can give me a light or even show me how to do it, I’d be grateful.

Waiting for good tips, hugs to everyone.

  • It is but exactly what is not working?

  • 1

    You won’t be missing session_start();? before the first if?

  • Hello Igor, you are not recording value’s in $_SESSION. And Miguel really I didn’t post session_start() here in the post, by forgetfulness, because I’m using a include Session.php server with all $_SESSION created.

  • I inserted session_start(), and I made some changes to make it work in a triggered way, that is not the way I would like, because I had to insert one more radio to be able to record both the value of the link and the other of the status. But I would like it to be with a single radio to record both values. If friends can give me a light of how I can perform such a task, I will be grateful. Thank you and hugs to all.

No answers

Browser other questions tagged

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