user2967081
user2967081

Reputation: 195

PHP: Pass a variable in URL via a clicked link

I created a function that requires one parameter to be passed into it but I need that parameter to come from another script. How do I embed the variable into a link then put that variable into the function in another script? I know I need to utilize $_GET, isset($_GET['']) and a href but I just can't put it all together.

Upvotes: 2

Views: 3182

Answers (2)

conquistador
conquistador

Reputation: 693

Use $_REQUEST['something']
Your link must be:

<a href="test.php?something=something&something1=test">Click Me</a>

Inside test.php

if(@$_REQUEST['something']=="something"){
    echo $_REQUEST['something1'];
    }

When you click Click Me, test.php would echo "test".

Upvotes: 1

Kenny Thompson
Kenny Thompson

Reputation: 1492

$_GET is collection of of query string parameters. If you had a url like: test.php?param1=foo&param2=bar you can access foo by $_GET['param1'] etc..

Upvotes: 5

Related Questions