Help with $_SESSION

Asked

Viewed 67 times

0

I want to take the values of a form and pass on another page of my site, but always gives 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 the 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?

  • 3

    Only the first echo is needed, the others are wrong. It is a concatenation and not printing.

4 answers

1

Try removing the ; from the end of the Session variable. When you use it this was you are finishing the echo together. Edit: As the colleague said, it only takes one echo to start concatenation. The rest can be removed

follow:

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

  • Oops, thank you, edited!

1

try so it probably won’t make any mistake

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

0

Only one echo is needed! To make it 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>';
?>

-1

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

Browser other questions tagged

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