Error displaying value

-1

I'm creating a list of contacts in php, and when I'm uploaded all the form data for it to display for me, it displayed: 1, not my data I entered.

<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
    <title>Adicionar contatos</title>
</head>
<body>
    <h1> Adicionar Contatos </h1>
    <form>
        <fieldset>
            <legend>Adicionar contato</legend>
            <label>
                Contato:
                <input type="text" name="numero">
                Nome:
                <input type="text" name="nome">
                Email:
                <input type="text" name="email">
            </label>
            <input type="submit" name="Cadastrar">
        </fieldset>
    </form>

    <?php
        $lista_contatos = array();

        if(isset($_GET['numero']) && isset($_GET['nome']) && isset($_GET['email'])){
            $_SESSION['lista_contatos'][] = $_GET[numero] && $_GET[nome] && $_GET[email];
        }

        if(isset($_SESSION['lista_contatos'])){
            $lista_contatos = $_SESSION['lista_contatos'];
        }
    ?>

    <table>
        <tr>
            <th>Contatos</th>
        </tr>

        <?php foreach ($lista_contatos as $contatos) : ?>
            <tr>
                <td><?php echo $contatos; ?></td>
            </tr>
        <?php endforeach; ?>
    </table>




</body>
</html>
    
asked by anonymous 06.09.2017 / 02:15

1 answer

0

Your problem is in this line

$_SESSION['lista_contatos'][] = $_GET[numero] && $_GET[nome] && $_GET[email];

To concatenate values use the

 $_GET[numero] . $_GET[nome] . $_GET[email];

So that you do not get together, add a space or whatever is convenient

 $_GET[numero] ." ". $_GET[nome] ." ". $_GET[email];

Your code is spinning around, these lines are just

<?php
   if(isset($_GET['numero']) && isset($_GET['nome']) && isset($_GET['email'])){
        $lista_contatos = array($_GET[numero],$_GET[nome],$_GET[email]);
        $_SESSION['lista_contatos']= $lista_contatos;
    }
 ?>
    
06.09.2017 / 02:55