Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2007
    Posts
    4

    Unanswered: PHP include wont work any ideas?

    Ive got some coursework with php and want to include many files but does not work, the files are stored in the same directory but comes up with this error:


    Warning: include(resources/layout.php) [function.include]: failed to open stream: No such file or directory in C:\WINDOWS\xampp\htdocs\css\New Folder\main.php on line 2

    Warning: include() [function.include]: Failed opening 'resources/layout.php' for inclusion (include_path='.;C:\WINDOWS\xampp\php\pear\') in C:\WINDOWS\xampp\htdocs\css\New Folder\main.php on line 2

    Fatal error: Call to undefined function pagetop() in C:\WINDOWS\xampp\htdocs\css\New Folder\main.php on line 4

    Any ideas would be very helpful thanks

  2. #2
    Join Date
    Mar 2007
    Posts
    28
    Please check your code

    it should be like

    <?
    php include("main.php");
    ?>
    Plus your host should allow you to use PHP!

    to check please create a new page and enter the following code


    <html>
    <head>
    <title>PHP Test</title>
    </head>
    <body>
    <?php phpinfo(); ?>
    </body>
    </html>
    Thanks

  3. #3
    Join Date
    Apr 2007
    Posts
    4
    php works but layout.php will not be included

  4. #4
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    the files are stored in the same directory but comes up with this error
    If you mean that the files to be included are in the same directory as the main.php file, then the following from the error message - resources/layout.php - indicates that your include statement looks something like - include "resources/layout.php"; or include("resources/layout.php");

    If you post your actual code, someone could probably help you in the first attempt.

  5. #5
    Join Date
    Apr 2007
    Posts
    4
    this is main.php

    <?
    php include("layout.php");
    ?>

    <? php
    pageTop("Student Feedback System");
    pageBanner("Main Page");
    pageStart();
    ?>
    <div id="leftsidebar">
    <a href="mainfeedback.html">Main page</a>
    <a href="givefeedback.php">Provide Feedback</a>
    <a href="results.php">See Results</a>
    </div>


    <h1>Student Feedback System</h1>
    <p>Welcome to the Student Feedback system.</p>
    <?php pageFinish(); ?>
    <div id="footer">
    <a href="mainfeedback.html">Main page</a>
    <a href="givefeedback.php">Provide Feedback</a>
    <a href="results.php">See Results</a>
    </div>

    <?php pageBottom(); ?>

    this is layout.php

    <?
    ################################################## ######################################
    # layout.php
    #
    #
    ################################################## ######################################

    function pageTop($pageTitle){
    print('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"');
    print('"http://www.w3.org/TR/html4/loose.dtd">');
    print('<html>');
    print('<head>');
    print('<link rel="stylesheet" href="resources/styles.css" type="text/css"> ');
    print(' <style type="text/css" media="all"> ');
    print(' @import "resources/styles.css";');
    print(' @import("resources/styles.css");');
    print(' </style>');
    print "<title>$pageTitle</title>";
    print('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">');
    print('</head>');
    print('<body>');
    };

    function pageStart(){
    print('<div id="main">');
    };

    function pageFinish(){
    print('</div>');
    };

    function pageBottom(){
    print('</body>');
    print('</html>');
    };

    function pageBanner($pagebanner){
    print('<div id="banner">');
    print('<h1>Student Feedback</h1>');
    print('<h2>We <i>really</i> value your feedback</h2>');
    print "<h3>$pagebanner</h3>";
    print('</div>');
    };

    function menu($divId, $menuItems)
    {
    print ('<div id="'.$divId.'">');
    $noOfMenuItems=count($menuItems);
    for($menuIndex=0;$menuIndex<$noOfMenuItems;$menuIn dex++){
    print "<a href=\"".$menuItems[$menuIndex][1]."\">".$menuItems[$menuIndex][0]."</a>";
    };
    print("</div>");
    };

    ?>

  6. #6
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    Is that code what it was before or after you changed it?

    This part, which is similar to what ganich gave as an example, is syntactically incorrect -
    PHP Code:
    <?
    php 
    include("layout.php");
    ?>
    Use <?php for all of your opening php tags. That code should be -
    PHP Code:
    <?php
    include("layout.php");
    ?>
    The line you posted right after the above -
    PHP Code:
    <? php
    appears to contain a space between the ? and the php and won't work as well.

    To get PHP to help you find errors, put the following two lines in after your first opening <?php tag -
    PHP Code:
    ini_set ("display_errors""1");
    error_reporting(E_ALL); 
    Also, a little advice. Don't repeatedly switch into and out of php mode unless it is necessary. The following code (with the above mentioned corrections) causes a blank line to be output to the browser -
    PHP Code:
    <?php
    include("layout.php");
    ?>
         <------ this is a new line that will be output to the browser
    <?php
    pageTop
    ("Student Feedback System");
    Just stay in PHP mode -
    PHP Code:
    <?php
    include("layout.php");

    pageTop("Student Feedback System");

  7. #7
    Join Date
    Apr 2007
    Posts
    4
    thanks thats been of help the error has moved to line 13 providing i have corrected everything ok

    <?php
    ini_set ("display_errors", "1");
    error_reporting(E_ALL);

    include ('layout.php');



    pageTop("Student Feedback System");
    pageBanner("Main Page");
    pageStart();

    <div id="leftsidebar">
    <a href="../New Folder/mainfeedback.html">Main page</a>
    <a href="../New Folder/givefeedback.php">Provide Feedback</a>
    <a href="../New Folder/results.php">See Results</a>
    </div>


    <h1>Student Feedback System</h1>
    <p>Welcome to the Student Feedback system.</p>
    pageFinish();
    <div id="footer">
    <a href="../New Folder/mainfeedback.html">Main page</a>
    <a href="../New Folder/givefeedback.php">Provide Feedback</a>
    <a href="../New Folder/results.php">See Results</a>
    </div>

    pageBottom(); ?>

    and comes out with

    Parse error: syntax error, unexpected '<' in C:\WINDOWS\xampp\htdocs\css\NewFolder\main.php on line 13

    thanks for all your help

  8. #8
    Join Date
    Mar 2007
    Posts
    28
    you are uploaded Php files in incorrect sequence. please donot use links like (../New Folder/results.php)

    rathar use http://website.com/NewFolder/results.php

    The layout file should be in the main directory and other main.php and other pages should be in sub directories.

    like include should be include ('New Folder/results.php');

    i think that may solve your problem..check your code and sytax again, make sure all your links are correct as i explained above.

  9. #9
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    In my post I wrote -
    Quote Originally Posted by dbmab
    Don't repeatedly switch into and out of php mode unless it is necessary.
    You have since removed all of the closing and opening php tags where you are outputting inline HTML code. It is necessary to switch out of PHP mode to output inline HTML code. So, put back in the PHP tags your took out that were before and after each block of inline HTML code.

    If you don't know which of these lines of code were inline HTML code (I am assuming that you wrote this code) and why the PHP tags were there and when it is necessary to have PHP tags, then you need to SLOW DOWN and go back and learn more of the basics about the HTML and PHP languages.

    If you are jumping in and attempting to write code without knowing the basics, you are dooming yourself to an endless list of error messages that will cause you frustration with what you are doing, at a time that it should be rewarding instead.

  10. #10
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    id check the path

    On my set ups I generally dump all the common stuff into a directory called
    incfiles


    using
    include ("./incfiles/<includefilename>.php");
    ..this usually gets round any relative path issues... ofrget t may be
    include ("../incfiles/<includefilename>.php");

    you error message is telling you that PHP cannot find the directory.. so thats the first thing id look for
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •