Function $ _SESSION does not work

1

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

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

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 that updates the data:

$_SESSION['endereco'] = $consulta["endereco"] ;
    
asked by anonymous 01.02.2018 / 01:01

1 answer

1

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

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

If the session is empty, when the HTML is generated, it would look like:

value=Rua Teste

And following the HTML specifications, the browser will only consider "Street" as the value of value and "Test" as a property. For everything to be considered as value you must enter the quotation marks:

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

It is also worth remembering that to use the information you can use the tags <?= ?> :

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

What are the advantages and disadvantages of using

01.02.2018 / 01:43