简体   繁体   中英

Passing variable to another php via a href

Im building a website where you need to see information of each client separately when clicking a button.

I already created the table with all of the clients but now when I want to pass the ID of the client(all of this from a database) when I click the link, it wont work. And also Im having problems with the "Undefined offset" error.

I already tried putting the SESSION outside of the while() statement but it only passes the last client's ID. Hope you can help me, here's the code

<tr>
                    <td >
                        <?php echo $row->Clave; //= $clave; 
                            $clave = $row->Clave;
                            $_SESSION['variable'] = $_GET[$clave]; //This is the ID.
                        ?>
                    </td>
                    //MORE ROWS
                    <td >
                        <a href="Ahorro/ahorro.php">Ir a ahorro</a> //This is where I want the ID to go to.
                    </td>

The home page already reads the ID of each row correctly, but doesnt send it, as I said.

You would use php's $GET to pass variables in the url.

<a href="Ahorro/ahorro.php/?clave=<?php echo $clave; ?>">

Would develop a url that looks like "Ahorro/ahorro.php/?clave=hello world" And in the other file you can access that variable like this:

echo $_GET["clave"];

Would echo out:

"Hello world"

Here is a link for more information:

http://php.net/manual/en/reserved.variables.get.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM