Pass variable via GET without action

2

I want to pass a variable to another page, I know I can use the GET method, however if <form method="GET" action="comentario.php"> is comentario.php it does not execute the commands to insert into the database (this code is on the same page), to insert would be <form method="GET" action=""> however the variable obviously is no longer recognized on the other page, (in this case the variable is $lang=$_GET['lang']; )
My question is how do I pass the variable to another page? As of now I'm not using Sessions . Home:

<form method="GET" action="">
    <table width="80%" align="center" cellpadding="8">
        <br><br>
        <tr>
            <td colspan="1" class="logo">
                <img src="imagens/logo.png" height="40" width="150">
            </td>
            <td class="idioma" align="right">
                <?php $lang=isset($_GET['lang']) ? $_GET["lang"] : false; ?>
                <select id="lang" name="lang" onchange="submitForm()">
                    <?php
                    switch ($lang) {
                        case 'en':
                        $lng=1;
                        break;
                        case 'fr':
                        $lng=2;
                        break;
                        case 'sp':
                        $lng=3;
                        break;
                        case 'de':
                        $lng=4;
                        break;
                        default:
                        $lng=0;
                    }
                    $questao=array('O que achou do nosso serviço?','ingles','frances','espanhol','alemao');

                    ?>
                    <option value="pt"<?php if($lang != 'fr' && $lang != 'en' && $lang != 'sp' && $lang != 'de'){ echo " selected=\"selected\"";} ?>>Português</option>
                    <option value="en"<?php if($lang == 'en'){ echo " selected=\"selected\"";} ?>>English</option>
                    <option value="fr"<?php if($lang == 'fr'){ echo " selected=\"selected\"";} ?>>Français</option>
                    <option value="sp"<?php if($lang == 'sp'){ echo " selected=\"selected\"";} ?>>Español</option>
                    <option value="de"<?php if($lang == 'de'){ echo " selected=\"selected\"";} ?>>Deutsch</option>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="3" class="pergunta" align="center">
                <hr>
                <?php echo $questao[$lng]; ?>
                <hr>
            </td>
        </tr>
        <tr>
            <td colspan="3" class="selecao">
                <div class="cores">
                    <input type="submit" name="verde" class="verde" value="verde">
                    <input type="submit" name="amarelo" class="amarelo" value="amarelo">
                    <input type="submit" name="vermelho" class="vermelho" value="vermelho">

                    <?php
                    date_default_timezone_set("Europe/Lisbon"); //definir zona
                    $data=date("Y-m-d"); //definir data
                    $hora = date("H:i:s"); //definir hora

                    if (isset($_GET['verde'])) {
                        $classificacao=$_GET['verde'];
                    }
                    elseif (isset($_GET['amarelo'])) {
                        $classificacao=$_GET['amarelo'];
                    }
                    elseif (isset($_GET['vermelho'])) {
                        $classificacao=$_GET['vermelho'];
                    }


                    if (isset($classificacao)) {
                        $inserir=mysqli_query($link,"INSERT INTO questionario (pergunta_id, pergunta, data, hora, idioma, origem, classificacao) VALUES ('','".$questao[$lng]."','$data','$hora','$lang', '','$classificacao')");
                        if (!$inserir) 
                        {
                            echo "Erro ao inserir na tabela.";
                        }
                        else
                        {
                            header('location: comentario.php');
                        }
                    }
                    ?>
                </div>


As you can see I did not insert anything into the action , only this way it works to insert the data into the database. Home The other page I want to pass the variable $lang=$_GET['lang'];

<td colspan="3" class="pergunta" align="center">
            <hr>
            <?php $lang=isset($_GET['lang']) ? $_GET["lang"] : false; 
            $lang=$_GET['lang'];

            if ($lang=='pt') {
                echo "Deixe aqui o seu comentário";
            }elseif ($lang == 'en')
            {
                echo "ENGLISH";
            }elseif ($lang=='sp')
            {
                echo "espanhol";
            }elseif ($lang=='de') {
                echo "alemao";
            }elseif ($lang=='fr') {
                echo "frances";
            }
            ?>

            <hr>
        </td>


If the action contains comentario.php (name of this page) this code works, otherwise it says Notice: Undefined index: lang in

    
asked by anonymous 05.06.2018 / 17:41

1 answer

1

I do not know if I understand, but to pass values to other pages you can use the URL, then use $ _RESQUEST to get the value.

Example:

você pode montar uma url no Href
<a href='comentario.php?lang=pt-br'>Acessar</a>
Url ficaria +/- assim
    http://pagina.com/comentario.php?lang=pt-br

No php você pode pegar o valor assim
    $lang= $_REQUEST["lang"];

This is a very simple example, sure to have other ways

    
05.06.2018 / 21:02