Member Offer
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP Problem

Discussion in 'Website Design Forum:' started by iEthan, Mar 29, 2009.

  1. iEthan

    iEthan Member

    So, I've created a script that sees if a XML file with the same name is in pgs/. If it is, it will grab the title and put it in $title, and grab the content and put it in $content. Now, I need to get $name. I've defined it in the test page. But, it is giving me the error that it is an undefined variable. But, I have defined it.

    Perhaps I should give you the code:

    display.php (the script that grabs the content and title)
    if(file_exists('pgs/' $name '.xml')){
    $getXML = new DOMDocument();
    $getXML->load('pgs/' $name '.xml');
    $getPage $getXML->getElementsByTagName("page");
    $getPage as $page){
    $getTitle $page->getElementsByTagName("title");
    $title $getTitle->item(0)->nodeValue;
    $getContent $page->getElementsByTagName("content");
    $content $getContent->item(0)->nodeValue;
    index.php (the test page)
    $name = 'index';
            <title>LiteManage Test</title>
        <h1><?php echo $title ?></h1>
        <p><?php echo $content ?></p>
    index.xml (the XML file that has the title and content.
    <?xml version="1.0"?><page>    <title>Home</title>    <content>        Hello. My name is Ethan.    </content></page>
    It is giving me the undefined error for $name, but it is clearly defined in index.php. How do I work around this?

    You may need clarification...
  2. darren

    darren Member

    Swap these around, $name has not been defined BEFORE you try to use it (display.php);


Share This Page