$_SESSION function does not work

Asked

Viewed 45 times

1

I am performing a process in my code, where the $_SESSION['test'] takes the value that returns from the bank, where it performs its function in parts, because if I have a single string, it loads the information perfectly, but if the string has space it does not recognize the whole value and brings the data in half. Example: if the bank returns the value "Test Street" the value that the $_SESSION returns is only "Street".

I wonder if the $_SESSION function does not recognize values with spacing and if there is any way to redeem this value and exchange the information between two PHP pages s.

Configuration.php:

<div class="col-md-9">
             <label>Endereço</label>
             <input type="text" class="form-control" id="end" name="end" value=<?php echo $_SESSION['endereco'] ?>><br>
         </div>

Php updating the data:

$_SESSION['endereco'] = $consulta["endereco"] ;
  • Can [Edit] the question and add trouble code?

1 answer

1


The problem is in your HTML, not in PHP. When doing:

value=<?php echo $_SESSION['endereco'] ?>

If the session has white space, when HTML is generated, it would be:

value=Rua Teste

And following the HTML specifications, the browser will consider only "Street" as value of value and "Test" as a property. So that everything is considered as value it will be necessary to insert the quotation marks:

value="<?php echo $_SESSION['endereco'] ?>"

Remember also that to read the information you can use the tags <?= ?>:

value="<?= $_SESSION['endereco'] ?>"

What are the advantages and disadvantages of using <? instead of <?php?

  • I had made a test this way, but forgot that I tested in a line without separation of space kk, it worked worth!

Browser other questions tagged

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