Set language in index.php

2

Good morning! Home I'm trying to develop a very simple system, contains 5 different languages, this part works fine, the problem is that when I enter for the first time on the site, in this case the file is the index.php , it shows the following error:

Afterchoosingalanguage,itisnormal,itonlyhappenswhenIfirstenter.Myquestionis:howdoIdefine"Portuguese" just as soon as the page finishes loading, for example the url be http://localhost:8080/.../?lang=pt %? Home This is a part of the code:

<select id="lang" name="lang" onchange="submitForm()">
                    <?php
                    switch ($_GET['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('Portugues','ingles','frances','espanhol','alemao');
                    ?>
                    <option value="pt"<?php if($_GET['lang'] != 'fr' && $_GET['lang'] != 'en' && $_GET['lang'] != 'sp' && $_GET['lang'] != 'de'){ echo " selected=\"selected\"";} ?>>Português</option>
                    <option value="en"<?php if ($_GET['lang'] == 'en'){ echo " selected=\"selected\"";} ?>>English</option>
                    <option value="fr"<?php if($_GET['lang'] == 'fr'){ echo " selected=\"selected\"";} ?>>Français</option>
                    <option value="sp"<?php if($_GET['lang'] == 'sp'){ echo " selected=\"selected\"";} ?>>Español</option>
                    <option value="de"<?php if($_GET['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>

Thank you in advance!

    
asked by anonymous 05.06.2018 / 10:37

0 answers