Jump to content

Recommended Posts

hey guys how you all doing? ok im really looking for some help i've been playing with this code for quite some time now and still not got the hang of it. i'm currently trying to code a dynamic website as a portfolio for my designs and im trying to get to view the news.php file with an 'id' to view in the index file using an include() but for some reason its not happening very well.

 

i keep getting the error message:

 

Warning: include(inc/news.php?id=) [function.include]: failed to open stream: No error in C:\xampplite\htdocs\lukerodham\old\index.php on line 218

 

Warning: include() [function.include]: Failed opening 'inc/news.php?id=' for inclusion (include_path='.;C:\xampplite\php\PEAR') in C:\xampplite\htdocs\lukerodham\old\index.php on line 218

 

just wondering if anyone could shed any light on what i may have done wrong :D thanks guys ive left part of the code below if this will help.

 

  <?php 
  $page = $_GET['page'];
  $news = $_GET['id'];
  
  if(!$page){
    getnews();
  }
  else {
    if($page = news){
        include("inc/news.php?id=".$news);
    }
    else 
        include("inc/".$page.".php");
  }
  ?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/235259-dynamic-page-help/
Share on other sites

Just include news.php and don't pass a query string to.

        include("inc/news.php");

$_GET['id'] in news.php will return the id passed to it from your parent script (index.php?page=news&id=123)

 

Before I said you can't pass a query string to an include. You can do this by using a url as the path

include "http://site.com/file.php?var=value"

However if you wish to use any variables from file.php within your parent script you wont be able to do this. This is because when you use a url as the path for an include only output from that file (text/html) will be returned. The raw php source code of that file will not be returned.

Link to comment
https://forums.phpfreaks.com/topic/235259-dynamic-page-help/#findComment-1208973
Share on other sites

No problem. Also another tip. When comparing values you should be using the comparison operator (==), not the assignment operator (=). String should always be wrapped in quotes. Otherwise PHP will think the word news is a constant rather than a string.

    if($page = news){

So that line should read

    if($page == 'news'){

Link to comment
https://forums.phpfreaks.com/topic/235259-dynamic-page-help/#findComment-1208977
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.