gladiator83x Posted June 13, 2006 Share Posted June 13, 2006 Hi All,I was just wondering if anyone could explain to me how to pass a variable from one file to another. I know that when there is a form involved, one can use:$variable_new = $_REQUEST['passed_variable] ;This works just fine, but I wanted to know if there were any other ways to pass variables to other files?Christopher [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /] Link to comment https://forums.phpfreaks.com/topic/11875-passing-variables/ Share on other sites More sharing options...
joquius Posted June 13, 2006 Share Posted June 13, 2006 you mean page.php?string=value ?this is <a href="?string=3">String is 3</a><? if (isset ($_GET['string'])) echo $_GET['string']; // 3 ?>you can do this on the same page, different pages, etc Link to comment https://forums.phpfreaks.com/topic/11875-passing-variables/#findComment-45072 Share on other sites More sharing options...
gladiator83x Posted June 13, 2006 Author Share Posted June 13, 2006 [!--quoteo(post=383319:date=Jun 13 2006, 11:32 AM:name=joquius)--][div class=\'quotetop\']QUOTE(joquius @ Jun 13 2006, 11:32 AM) [snapback]383319[/snapback][/div][div class=\'quotemain\'][!--quotec--]you mean page.php?string=value ?this is <a href="?string=3">String is 3</a><? if (isset ($_GET['string'])) echo $_GET['string']; // 3 ?>you can do this on the same page, different pages, etc[/quote]Thanks Joquius, that helped me out big time. I was trying to switch it around a little bit though and I couldn't get this to work:<a href=file_2.php?string=$hlink>String is 3</a><a href="?string=">String is 3</a><? if (isset ($_GET['string'])) echo $_GET['string']; // 3 ?>$hlink is my variable name and I am trying to return what it is on another page; however, all I am returning is the word $hlink. Any suggestions? I am stumped. Link to comment https://forums.phpfreaks.com/topic/11875-passing-variables/#findComment-45154 Share on other sites More sharing options...
ober Posted June 13, 2006 Share Posted June 13, 2006 <a href=file_2.php?string=$hlink>String is 3</a>You're not using quotes around the href, PLUS $hlink is a php variable.... you need to put it inside PHP tags:<a href="file_2.php?string=<?=$hlink?>">String is 3</a> Link to comment https://forums.phpfreaks.com/topic/11875-passing-variables/#findComment-45162 Share on other sites More sharing options...
gladiator83x Posted June 13, 2006 Author Share Posted June 13, 2006 [!--quoteo(post=383411:date=Jun 13 2006, 02:33 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Jun 13 2006, 02:33 PM) [snapback]383411[/snapback][/div][div class=\'quotemain\'][!--quotec--]<a href=file_2.php?string=$hlink>String is 3</a>You're not using quotes around the href, PLUS $hlink is a php variable.... you need to put it inside PHP tags:<a href="file_2.php?string=<?=$hlink?>">String is 3</a>[/quote]Thanks Ober!!! You're the Man [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Link to comment https://forums.phpfreaks.com/topic/11875-passing-variables/#findComment-45164 Share on other sites More sharing options...
gladiator83x Posted June 13, 2006 Author Share Posted June 13, 2006 [!--quoteo(post=383413:date=Jun 13 2006, 02:40 PM:name=gladiator83x)--][div class=\'quotetop\']QUOTE(gladiator83x @ Jun 13 2006, 02:40 PM) [snapback]383413[/snapback][/div][div class=\'quotemain\'][!--quotec--]Thanks Ober!!! You're the Man [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /][/quote]Actually, that did not quite work right. All my code was already in php brackets. I am just echoing the html code. So the code below won't work either, It is what I already have. <a href="file_2.php?string=<?=$hlink?>">String is 3</a>A snippet of my code is :<php// just the last several lines of my codeecho '<a href=review_end1.php?string11=$hlink>String is 3</a>';// this also has the same output asecho '<a href="review_end1.php?string11=$hlink">String is 3</a>';// Free resultsetmysql_free_result($result);// Closing connectionmysql_close($link);?>The double quotes did not matter. I am still returning "$hlink", instead of what $hlink holds. Any other suggestions? Link to comment https://forums.phpfreaks.com/topic/11875-passing-variables/#findComment-45175 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.