Pass variable value inside text with echo [closed]

0

I'm trying to add a value to a variable within a text with echo and I'm not getting it, the value is available because I can access it.

What I have is this, I could not enter the code properly, so the image:

LookingattheconsoleofChromeIhavethis:

print_r ($ _ SESSION) result:

Array ( [usuarioID] => 124 [nomeUsuario] => Valter Ferreira Martins [email] => [email protected] [IdCategoria] => 0 [Cliente] => 4 [produtos_1417] => 13 [produtos_1676] => 0 [produtos_1207] => 0 [produtos_1306] => 1 [produtos_1508] => 1 )

When I position the mouse pointer over the Add variable button it is no value, but in the console the value is available.

    
asked by anonymous 29.12.2016 / 13:57

3 answers

2

The link in the image looks wrong, has a double quotation mark left, remove it

Change:

<a href="produtos.php?Cliente="'.$_SESSION['Cliente'] .'" class="btn ....
aspa a mais ------------------^
                                    
29.12.2016 / 14:17
1

Variables can only receive the value inside double quotation marks. Simple quotes are for literals in PHP.

Right:

echo "$minhaVariavel";

Wrong:

echo '$minhaVariavel';
    
29.12.2016 / 14:14
1

To use echo in php you need to use double quotes or concatenate, the php code always stays within <?php ... ?> in html.

<?php
   $variavel = 123;

   //aspas duplas permite usar variaveis sem concatenar
   echo "<p>o numero é $variavel</p>";

   // ou 
   echo '<p>o numero é '.$variavel.'</p>';

?>
    
29.12.2016 / 14:13