Error while displaying value

Asked

Viewed 28 times

-2

I am creating a contact list in php, and when I am sent all the data of the form for it to display to me, it displayed: 1, not my data that 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>
  • Could you be more specific? I don’t understand your problem. Ask a [tour] to create a good question.

1 answer

0


Your problem is on that line

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

To concatenate values use the point

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

So they don’t get together add a space or whatever is convenient

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

Your code is spinning around, just these lines

<?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;
    }
 ?>

Browser other questions tagged

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