how to have a variable take a value from one page and move to another

Asked

Viewed 32 times

-2

I have this code below.

<?php
       include '../conexao.php';

       $sth = $pdo->prepare('SELECT * FROM comanda');
       $sth->execute();
       ?>
      
                       <?php
                       foreach ($sth as $res) {
                           extract($res);
                       ?>
                           <center>
                               <ul>
                                   <a href="#.php"><img id="efeito" src="../img/<?= $num_com ?>.png"></a>
                               </ul>
                           </center>
                       <?php
                       }
                       ?>

inserir a descrição da imagem aqui

here the code line with the "href" brings a data from the bank and uses in the $num_com.
I need to make sure that when I select a command(image) it takes the specific value of the variable and stores in another to be used in an Index in the future.
how can I do this ?

thanks in advance for the attention.

1 answer

0


can do by creating a "GET Receiver" on and perform an Insert function on the database.

I will demonstrate the logic and you implement according to your scenario!

  1. First, let’s imagine that below is where the value will come:

www.localhost/pegaValor? value=2 <- Here we have the value 2 being passed through the GET method in a variable called value

  1. Then you need to receive this value, in case we will receive on the page: catch that will stay that way:

$value = $_GET['value']; <- Here is where you will receive the value, from here is success, you now just need to give an input in the BD.

$sql = "Insert into TABLE ('column name') VALUE = '$value';"

Study: Pass by $_GET and $_POST (These you should master)

  • Thanks for the tip, but I couldn’t execute. , when clicking on an image, the value of the image is directed to another pg and stored in a variable. ali como você me disse, I would need name for each image to make it work, there I basically made an array and made it display the images until reaching the last number available in the bank

  • You can pass value using: <a href="pageRecebevalor? value=142"> <img src="camiodaimg.png"> </a>

  • has worked well, thank you very much for the attention and the tip. success and happiness to you.

  • Don’t forget to check to show others how to solve the problem <3 until next time.

Browser other questions tagged

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