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 Link to comment https://forums.phpfreaks.com/topic/58464-solved-passing-variable-through-the-query-string/ 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. Link to comment https://forums.phpfreaks.com/topic/58464-solved-passing-variable-through-the-query-string/#findComment-289928 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.