Jump to content

[SOLVED] Passing Variable through the Query String


hanlonj

Recommended Posts

Hi, I am just trying to get to grips with passing a variable through a query string from one script to another. So I want to declare a variable e.g. $myString on the first page. I then want to append it to a link e.g.

 

<?php
  
   $myString = "This is my String!";

?>

// back to the html part of the page
<a href = "anotherPage.php?<?php $myString ?>">Another Page</a>

 

I then want the "anotherPage.php" to print the contents of $myString to the screen.

 

 

My attempt is this but it's not working:

 

<?php

$_GET[$myString];

echo "$myString";

?>

 

Can anyone help here please?

 

hj

<?php
  
   $myString = "This is my String!";

?>

// back to the html part of the page
<a href = "anotherPage.php?var=<?php echo urlencode($myString) ?>">Another Page</a>

 

Then...

 

<?php

  if (isset($_GET['var'])) {
    echo urldecode($_GET['var']);
  }

?>

 

You really only need urlencode because there are spaces in your string.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.