hanlonj Posted July 4, 2007 Share Posted July 4, 2007 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 Quote Link to comment Share on other sites More sharing options...
trq Posted July 4, 2007 Share Posted July 4, 2007 <?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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.