Note that there are some explanatory texts on larger screens.

plurals
  1. POConfused over something occuring with includes + echo
    text
    copied!<p>My issue is as follows below, if anyone could help explain why the following is happening, and how to fix it; that would be amazing!</p> <p>The long and short of my problem is that i have written some code (that completely works when within the main script!), but I need to place this code within multiple scripts. Therefore I have tried making this code into an 'include' file.</p> <p>When the include file is executed, only the 'echo "TEST";' from the '$_GET['ffd'];' variable gets written to the HTML page. I'm highly confused about why it matters - as the other things should be written to the page regardless... the 'echo' statements below the { _ _ } of the '$_GET['ffd'];' are never written to the HTML page.</p> <p>I know the files exist because when the script is ran within the main script (without the includes) it finds the files and correctly places the forms on the HTML page.</p> <p>This is the includes in the main script I have been using. (when I move the code from the main script to the includes file)</p> <pre><code>include("includes/forcedlfile.inc"); </code></pre> <p>The contents of the includes file are IDENTICAL to the contents of the PHP script shown at the bottom (i.e. copied and pasted) when ran within the main PHP script or the included .inc file.</p> <p>Script being executed:</p> <pre><code> //THE BIT THAT ALWAYS ECHO's TO THE HTML PAGE if(isset($_GET['ffd'])) { echo "TEST"; //OTHER THINGS NOT RELEVANT HERE } //CODE THAT SHOULD BE EXECUTED REGARDLESS OF BEING WITHIN THE MAIN BODY OF THE SCRIPT OR WITHIN AN INCLUDES FILE $homeworkid_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'homeworktasks' . DIRECTORY_SEPARATOR . $chosenhomework; if (file_exists($homeworkid_dir)) { echo "&lt;b&gt;Download Homework Attachments: &lt;/b&gt;"; $attachmentno = 0; $contents = array_diff(scandir($homeworkid_dir, 1), array('..', '.', '.htaccess')); foreach($contents as $file) { $attachmentno = $attachmentno + 1; $file_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'homeworktasks' . DIRECTORY_SEPARATOR . $chosenhomework . DIRECTORY_SEPARATOR . $file; $btn = explode(DIRECTORY_SEPARATOR, $file_dir); $btn = end($btn); $dllink = end($fsh); //ONLY WRITTEN TO PAGE WHEN WITHIN THE ORIGINAL SCRIPT, NOT 'INCLUDE' FILE echo "&lt;form action='".$dllink."?tsk=".$homeworkid."&amp;ffd=y' method='post'&gt; Attachment ".$attachmentno.": &lt;input type='hidden' name='dldir' value='".$file_dir."'&gt; &lt;input type='hidden' name='homeworkid' value='".$homeworkid."'&gt; &lt;input type='submit' value='Click Here To Download: ".$btn."'&gt; &lt;/form&gt;"; } } </code></pre> <p>If I place the file within the includes <strong>and</strong> the main script and submit the form (from the main script) I end up with two lots of 'TEST' appearing on the screen, and ONLY ONE form submission button - when <strong>I should have two</strong>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload