SpireLink Posted August 1, 2007 Share Posted August 1, 2007 Hi, I have a secript that is graping data from data base .. my folders are like this docs --includes . ....etc in the docs folder there is a file called channels.php and it have this code <?php $id = trim($HTTP_GET_VARS[id]); include('includes/funcetion_channels.php?channel=$id'); ?> in the includes folder there is a funcetion_channels.php with this code inside <?php include("config.php"); $channel = trim($HTTP_GET_VARS[id]); if ($channel == "main") { Case 1 Actions } else { Case 2 Actions } ?> now when i call the funcetion.php it gives me this error Warning: Failed opening 'includes/funcetion_channels.php?channel=$id' for inclusion (include_path='.;c:\php4\pear') in c:\phpdev5\www\alaineye\channel.php on line 3 while when i run the funcetion_channels.php file sending the channel paramter in the url i can get data, which means it works very fine ... how can i include the funcetion_channels.php inside the channels.php file while to get the data of a specified channel using the funcetions inside the funcetion_channels.php file ... notice that i call the channels.php file using this url channels.php?id=1 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/ Share on other sites More sharing options...
b1011 Posted August 1, 2007 Share Posted August 1, 2007 my friend was having this problem You can use $_GET in an include function (.php?something=123) Youll need to include the file then on that file have a function in witch you can pass the variable to. Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-312907 Share on other sites More sharing options...
Caesar Posted August 1, 2007 Share Posted August 1, 2007 include('includes/funcetion_channels.php?channel=$id'); That's incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-312910 Share on other sites More sharing options...
SpireLink Posted August 1, 2007 Author Share Posted August 1, 2007 my friend was having this problem You can use $_GET in an include function (.php?something=123) Youll need to include the file then on that file have a function in witch you can pass the variable to. sir, i cant include the file without setting the channel variable, because it will do Case 1 Actions which will not get the data i want, it will run another query Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-312915 Share on other sites More sharing options...
wildteen88 Posted August 1, 2007 Share Posted August 1, 2007 Variables only work if you place them inside double quotes. If you place a variable within a single quote PHP will treat it as text. In your case PHP is doing just that. It is trying to include a file called funcetion_channels.php?channel=$id within includes/ Also as a side note you can only use url parameters within an include if php has url_fopen (or url_include if your site runs on PHP5.2.x) enabled within the php.ini. Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-312919 Share on other sites More sharing options...
SpireLink Posted August 1, 2007 Author Share Posted August 1, 2007 include('includes/funcetion_channels.php?channel=$id'); That's incorrect. ok , could you please correct me?? Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-312936 Share on other sites More sharing options...
wildteen88 Posted August 1, 2007 Share Posted August 1, 2007 Variables only work if you place them inside double quotes. If you place a variable within a single quote PHP will treat it as text. In your case PHP is doing just that. It is trying to include a file called funcetion_channels.php?channel=$id within includes/ Also as a side note you can only use url parameters within an include if php has url_fopen (or url_include if your site runs on PHP5.2.x) enabled within the php.ini. Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-312939 Share on other sites More sharing options...
SpireLink Posted August 1, 2007 Author Share Posted August 1, 2007 Variables only work if you place them inside double quotes. If you place a variable within a single quote PHP will treat it as text. In your case PHP is doing just that. It is trying to include a file called funcetion_channels.php?channel=$id within includes/ Also as a side note you can only use url parameters within an include if php has url_fopen (or url_include if your site runs on PHP5.2.x) enabled within the php.ini. ok i changed the code to be include("includes/funcetion_channels.php?channel=$id"); and i got the same error, more over am working on php 4.2.2 Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-312971 Share on other sites More sharing options...
wildteen88 Posted August 1, 2007 Share Posted August 1, 2007 Are you sure its the same exact error? the id variable should now be being parsed resulting in php including a file called funcetion_channels.php?channel=value_of_id_var_here eg if $id was set to the number 2 it'll be funcetion_channels.php?channel=2 Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-312980 Share on other sites More sharing options...
SpireLink Posted August 1, 2007 Author Share Posted August 1, 2007 Are you sure its the same exact error? the id variable should now be being parsed resulting in php including a file called funcetion_channels.php?channel=value_of_id_var_here eg if $id was set to the number 2 it'll be funcetion_channels.php?channel=2 this is the message Warning: Failed opening 'includes/funcetion_channels.php?channel=1' for inclusion (include_path='.;c:\php4\pear') in c:\phpdev5\www\alaineye\channel.php on line 3 Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-312991 Share on other sites More sharing options...
wildteen88 Posted August 1, 2007 Share Posted August 1, 2007 Yep its parsing your variable but it cant find the file funcetion_channels.php is that file name spelt correctly? To me it looks like it is supposed to be function_channels.php Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-313011 Share on other sites More sharing options...
SpireLink Posted August 1, 2007 Author Share Posted August 1, 2007 Yep its parsing your variable but it cant find the file funcetion_channels.php is that file name spelt correctly? To me it looks like it is supposed to be function_channels.php thanks , i have changed the file name, and used the same name in the code, but stell getting the error <?php $id = trim($HTTP_GET_VARS[id]); include("includes/function_channels.php?channel=$id"); ?> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-313019 Share on other sites More sharing options...
wildteen88 Posted August 1, 2007 Share Posted August 1, 2007 Can you run a php script with just phpinfo() in it for me and then scroll down and look for the following lines: url_fopen url_include (if it exists) What are their values? Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-313024 Share on other sites More sharing options...
SpireLink Posted August 1, 2007 Author Share Posted August 1, 2007 Can you run a php script with just phpinfo() in it for me and then scroll down and look for the following lines: url_fopen url_include (if it exists) What are their values? I cant find it there, I only founded allow_url_fopen / Local Value 1 / Master Value 1 Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-313040 Share on other sites More sharing options...
wildteen88 Posted August 1, 2007 Share Posted August 1, 2007 What happens if you use a web address in the include $id = trim($_GET['id']); include("http://mysite.com/includes/function_channels.php?channel=$id"); Change http://mysite.com/ to your websites address. I think you can only use url parameters if you are using a url path rather than a filesystem path. Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-313061 Share on other sites More sharing options...
SpireLink Posted August 1, 2007 Author Share Posted August 1, 2007 What happens if you use a web address in the include $id = trim($_GET['id']); include("http://mysite.com/includes/function_channels.php?channel=$id"); Change http://mysite.com/ to your websites address. I think you can only use url parameters if you are using a url path rather than a filesystem path. ok, i tried something elese i moved the function_channels.php to the same directory of channel.php , and i got the same error Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-313070 Share on other sites More sharing options...
wildteen88 Posted August 1, 2007 Share Posted August 1, 2007 Did you try it a url instead? I am pretty sure you can only use url parameters (?channel=$id - thats what I mean by a url parameter) within includes if you use a url path. Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-313076 Share on other sites More sharing options...
SpireLink Posted August 1, 2007 Author Share Posted August 1, 2007 i fixed it another way 1st in the function_channels.php i changed include("config.php"); $channel = trim($HTTP_GET_VARS[channel]); if ($channel == "main") to be include("config.php"); if ($channel == "main") than , in channels.php i changed the code to be $channel = trim($HTTP_GET_VARS[id]); include("includes/function_channels.php"); so in this case , i defined the channel vriable, and after that i included the function_channels.php , and while the $channel is predefined it will not ask for it again it will contenue to work and run the SQL command using the defined value thanks for assistance Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-313091 Share on other sites More sharing options...
Caesar Posted August 1, 2007 Share Posted August 1, 2007 Might seem like a strange question but...why take such an approach to including a file to your script? Even if the function you're including is dependent on the value you're trying to pass to it here...there are easier and less problematic approaches. Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-313349 Share on other sites More sharing options...
SpireLink Posted August 2, 2007 Author Share Posted August 2, 2007 Might seem like a strange question but...why take such an approach to including a file to your script? Even if the function you're including is dependent on the value you're trying to pass to it here...there are easier and less problematic approaches. Sir, You are totaly right, but I am using some functions many times in the project, and including or calling the functions will make it easier for me to fix bugs, more over regarding that value that i pass it will be used in many other files, because once you call the channel.php file, it will call functions_channel.php functions_news.php functions_calendar.php functions_adserv.php which will make some queries accourding to the $channel value. Quote Link to comment https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/#findComment-314013 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.