mnybud Posted December 27, 2008 Share Posted December 27, 2008 Newbie questions time I am trying to accomplish the following: I have a url formated like this: http://www.domain.com/?word_I_want=thisword I can echo "thisword" fine on my page with <?PHP echo $_REQUEST['word_I_want']; ?> But I also need to include it within this after ?query= <?PHP include("parser.php?query=word_I_want") ?> I know this should be simple but I have tried several variations of what I thought might work and keep getting syntax errors. Can anyone help me out please? Quote Link to comment https://forums.phpfreaks.com/topic/138540-solved-echo-inside-include/ Share on other sites More sharing options...
JasonLewis Posted December 27, 2008 Share Posted December 27, 2008 All you need to do is retrieve the variable THEN include the file and due to the scope of the variable it should be accessible in the included file. $variable = $_GET['word_I_want']; include("page.php"); page.php: echo $variable; Also, use $_GET for retrieving variables from the URL, not $_REQUEST because that also stores the $_POST variables. You're better off specifying the one you want. Quote Link to comment https://forums.phpfreaks.com/topic/138540-solved-echo-inside-include/#findComment-724351 Share on other sites More sharing options...
mnybud Posted December 27, 2008 Author Share Posted December 27, 2008 Hi thanks for the reply and I understand the best way would be to echo the $variable; in the included php directly but that page is complex and over my head to edit. Is there a way I can just echo it within the include on the actual page like I asked above? Quote Link to comment https://forums.phpfreaks.com/topic/138540-solved-echo-inside-include/#findComment-724357 Share on other sites More sharing options...
timmah1 Posted December 27, 2008 Share Posted December 27, 2008 Why couldn't you just do like this? $variable = $_GET['word_I_want']; include("parser.php?query=".$variable.""); Quote Link to comment https://forums.phpfreaks.com/topic/138540-solved-echo-inside-include/#findComment-724358 Share on other sites More sharing options...
mnybud Posted December 27, 2008 Author Share Posted December 27, 2008 you rock. thanks much!! Quote Link to comment https://forums.phpfreaks.com/topic/138540-solved-echo-inside-include/#findComment-724361 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.