pass parameters with PHP

0

I'm trying to click on an image to pass the parameters I need to the other page.

<a href="todoeventos.php?variable=<?php print $variable ["imagenes"]?>">

With this I can pass the image to the other php file, but I also need to pass name_evento location and price.

I've tried doing something like that but it does not work

<a href="todoeventos.php?variable=<?php print $variable ["imagenes"]?>dos=<?php print $dos ["imagenes"]?>">

and this is all my code

    <div class="row">
<?php
while ($variable = $consultaimg->fetch_assoc())
{

  ?>
  <div class="col-md-4">
    <div class="thumbnail">


      <a href="todoeventos.php?variable=<?php print $variable ["imagenes"]?>">

        <img src="<?php print $variable["imagenes"]?>" style="width:100%">
        <div class="caption">
          <p >Nombre evento: <?php print $variable ["nombre_evento"]?></p>
          <p>Localizacion:<?php print $variable ["localizacion"]?></p>
          <p>Precio de la entrada: <?php print $variable ["precio"]?></p>
        </div>
      </a>
    </div>
  </div>

  <?php

}

? >

    
asked by NuriaOveeeeeeejero 20.02.2018 в 20:20
source

3 answers

0

You can pass all the parameters by the URL, using the GET method, example:

<a href="destino.php?variable1=valor1&variable2=valor2&...">Mi enlace</a>

GET method: An associative array of variables passed to the current script via URL parameters.

It would look like this:

<a href="todoeventos.php?variable=<?php echo $variable["imagenes"]?>&localizacion=<?php echo $variable["localizacion"] ?>&precio=<?php echo $variable["precio"] ?>">

You receive this in your file todoeventos.php

$imagenes = $_GET["imagenes"];
$localizacion= $_GET["localizacion"];
$precio= $_GET["precio"];

I hope it serves you.

    
answered by 20.02.2018 / 20:39
source
0

When passing more than one parameter from one page to another it is necessary to add between each of them a &

 http://url.php?parametro1=valor1&parametro2=valor2

Keeping your PHP / HTML code in this way:

 <a href="todoeventos.php?variable=<?php print $variable ["imagenes"]?>&dos=<?php print $dos ["imagenes"]?>">
    
answered by 20.02.2018 в 20:36
0

Your link would be this way for example: (to go joining variables the "&" is used)

<a href="post.php?id=123&date=2018-02-20"> Link al post 123 </a>

And in your post.php to consume the data, you should receive it by GET like this:

<?php
    echo $_GET['id']; // en este caso imprimirá "123"
    echo $_GET['date']; // en este caso imprimirá "2018-02-20"
?>

(although then you must sanitize all the data received by GET to avoid SQL injections and others)

    
answered by 20.02.2018 в 20:37