how to pass value by href with php with get method?

1

I'm passing a value using href with php and get method but I think my syntax is wrong since it does not recognize me in the url this is my code

$dni=09309393;
   echo'
     <label id="msjgd">EL PACIENTE SE REGISTRO CORRECTAMENTE EN LA PRIMERA FASE</label><br>
      <a id="cclinico" href="tarjeta.php?dni=$dni">CLICK PARA REGISTRAR CONTROL CLINICO</a>
    ';  

but in the url I get card.php? dni = $ dni and you should leave tarjeta.php? dni = 09309393

thanks

    
asked by ingswsm 06.07.2017 в 22:26
source

4 answers

3

It is because to concatenate this variable of PHP , invoking the method echo with ' is imperative that the ones with .

$dni=09309393;
   echo'
     <label id="msjgd">EL PACIENTE SE REGISTRO CORRECTAMENTE EN LA PRIMERA FASE</label><br>
      <a id="cclinico" href="tarjeta.php?dni=' . $dni . '">CLICK PARA REGISTRAR CONTROL CLINICO</a>
    ';  

You can directly reference this variable only if you use " instead of ' .

    
answered by 06.07.2017 в 22:29
0

If you need your ID to have that 0 from the beginning you have to use it as String

$dni="09309393";

Now you can concatenate with the . but it is easier to change the type of quotes that you use, with the double quotes PHP will detect the variables within your string:

echo"
 <label id='msjgd'>EL PACIENTE SE REGISTRO CORRECTAMENTE EN LA PRIMERA FASE</label><br>
  <a id='cclinico' href='tarjeta.php?dni=$dni'>CLICK PARA REGISTRAR CONTROL CLINICO</a>
";  
    
answered by 06.07.2017 в 22:35
0

try doing the same but instead of ' use ", another option is that at the moment show your variable do this:

$dni=09309393;
   echo'
     <label id="msjgd">EL PACIENTE SE REGISTRO CORRECTAMENTE EN LA PRIMERA FASE</label><br>
      <a id="cclinico" href="tarjeta.php?dni='.$dni.'">CLICK PARA REGISTRAR CONTROL CLINICO</a>
    ';
    
answered by 06.07.2017 в 23:18
0

It's strange, but usually people fight with the 'and the' ones of the chained. "My solution is usually the following:

$dni=09309393;
$result = sprintf('
  <label id="msjgd">EL PACIENTE SE REGISTRO CORRECTAMENTE EN LA PRIMERA FASE</label><br>
  <a id="cclinico" href="tarjeta.php?dni=%s">CLICK PARA REGISTRAR CONTROL CLINICO</a>',
  $dni); 

echo $result;

that is, use the function sprintf () in which you indicate the pattern string, and the variables with the corresponding%.

This as an example, you can always simplify and remove variables ...

    
answered by 07.07.2017 в 11:27