Help with $ _SESSION [closed]

0

I want to get the values of a form and pass on another page of my site, but it always gives an error.

Code where the values are:

<form id="formulario" name="form" action="login.php" method="post" onsubmit="return validacao()"/>

<?php
   session_start();
   $_SESSION['bairro'] = $_POST['tBairro'];
   $_SESSION['rua'] = $_POST['tRua'];
   $_SESSION['numero'] = $_POST['tNum'];
   $_SESSION['cidade'] = $_POST['tCidade'];
   $_SESSION['estado'] = $_POST['tEstado'];

?>

Code where I want to pass values:

<?php
  session_start();
  echo '<span>Endereço para a entrega 01: ' . echo $_SESSION['bairro'];  '-' . echo $_SESSION['rua']; ',' echo $_SESSION['numero']; . '-'  . echo $_SESSION['cidade'] . '/' . echo $_SESSION['estado'];'</span>'
?>

Error:

PHP Parse error: syntax error, unexpected 'echo' (T_ECHO)

What can I do?

    
asked by anonymous 21.06.2018 / 18:40

4 answers

1

So try it will probably not give any error

<?php 
session_start(); 
?>
<span>Endereço para a entrega 01:
<?php echo $_SESSION['bairro'];?> -
<?php echo $_SESSION['rua'];?> ,
<?php echo $_SESSION['numero'];?> -
<?php echo $_SESSION['cidade'];?> /
<?php echo $_SESSION['estado'];?>
</span>
    
21.06.2018 / 19:12
1

Try removing the; end of the variable session. When you use it, you were ending the echo together. Edit: As the colleague said, you only need one echo to start the concatenation. The rest can be removed

follows:

<?php
  session_start();
  echo '<span>Endereço para a entrega 01: ' . $_SESSION['bairro'] .  '-' . $_SESSION['rua']. ','. $_SESSION['numero'] . '-'  .  $_SESSION['cidade'] . '/' . $_SESSION['estado'] '</span>' ;
?>
    
21.06.2018 / 18:44
0

Only one echo is needed! To be more readable, do so:

<?php
  session_start();
  echo '<span>Endereço para a entrega 01: '
           .$_SESSION['bairro']
           .'-'.$_SESSION['rua']
           .','.$_SESSION['numero']
           .'-'.$_SESSION['cidade']
           .'/'.$_SESSION['estado']
       .'</span>';
?>
    
21.06.2018 / 18:54
-1

Solved! I left only echo and ended ; at the end of < /span > and it worked.

    
21.06.2018 / 19:06