8

Blocks or pieces of PHP code are showing up in my web page suddenly as though they are not being recognized as PHP code. I had it working just find before and I can't think of anything I've changed or done that would have stopped it from working! I spent so long getting Apache, MySQL and PHP working together in the first place and now this. I am ready to tear my hair out!!

Example 1: Example 1 Example 1 code: (note that one php code block is showing up in the web page, while the other is not!)

<fieldset>
    <legend>Enter SELECT statement:</legend>
    <textarea name="select" style="width: 100%; margin-bottom: 10px;">
        <?php
            if (isset($_POST['select'])
                echo $_POST['select'];
        ?>
    </textarea>
    <input type="submit" value="Search" />
    <!-- display any sql errors here -->
    <?php
        echo "hello world!";
        if (isset($_POST['select']) {
            if (!$results = mysql_query($_POST['select']))
                die("Error: " . mysql_error());
        }
    ?>
</fieldset>

Example 2: Example 2

Example 2 code:

<fieldset>
    <legend>Tags:</legend>
    <table class="tagstable">
        <tr class="tagsrow">

        </tr>
        <?php
            $query = "SHOW COLUMNS FROM recipes LIKE 'Tags'";
            if (!($ret = mysql_query($query)))
                die("Error - could not show columns: " . mysql_error());

            if(mysql_num_rows($ret)>0){
                $row=mysql_fetch_row($ret);
                $options=explode("','",preg_replace("/(enum|set)\('(.+?)'\)/","\\2",$row[1]));
            }

            foreach ($options as $tag) {
                echo '<script type="text/javascript">addTag("' . $tag . '", false)</script>';
            }
        ?>
    </table>
    <br>
    <input type="text" id="addtag"><input type="submit" value="Add">
</fieldset>

Troubleshooting:

  • My phpinfo(); page works as expected
  • Folder containing php.exe is included in my PATH
  • Tried restarting Apache
  • Followed all steps in the answer to this question
  • Using Apache 2.2.22, MySQL Server 5.5.24, PHP 5.4.3, Windows 7

Apache httpd.conf contains:

LoadModule php5_module "c:/websites/php/php5apache2_2.dll"
<IfModule dir_module>
  DirectoryIndex index.html index.htm index.php
</IfModule>
AddType application/x-httpd-php .php
PHPIniDir "C:/websites/php"

Anything left that I haven't thought of??

Thank you!

Community
  • 1
  • 1
bumbleshoot
  • 1,082
  • 2
  • 17
  • 32
  • Are you sure the second snippet in the 1st example just isn't "hidden" (as in, removed from view by the browser because it's trying to parse it as HTML)? View the page source, do you see the second PHP snippet? – nickb Jul 10 '12 at 00:09
  • @nickb: I do see the second PHP snippet in the page source, however its color is green, which is the same color as comments. The color of the first PHP snippet is black. – bumbleshoot Jul 10 '12 at 00:17
  • @jessica - What is the file extension of these files? `.htm`? `.html`? `.php`? – nickb Jul 10 '12 at 00:18
  • @nickb: The file extension is .php – bumbleshoot Jul 10 '12 at 00:19
  • @JoeCortopassi: I'm not sure what you mean by error logs - sorry I'm very new to PHP! Could you explain? – bumbleshoot Jul 10 '12 at 00:20
  • any time php or apache has an error, they write it to their log. What are you running apache on (Windows, Linux, OSX)? – JoeCortopassi Jul 10 '12 at 00:24
  • @JoeCortopassi: Windows 7. I've added all contents of httpd.conf related to PHP to my post. – bumbleshoot Jul 10 '12 at 00:27
  • IMO 100 points to @jessica, this was a good question. – jay Jul 10 '12 at 00:34

1 Answers1

4

What's the path to the phpinfo() page? Compare that to the path that your using to access your script. My guess (by when you say that "php.exe is included in my PATH"), is that you aren't accessing the file in your web root, but rather trying to directly access it through the file system. You need to access it through the webserver. If you do this right, it will probably look like:

http://localhost/myscript.php
JoeCortopassi
  • 5,083
  • 7
  • 37
  • 65
  • 2
    HAH! You're right. I feel like an idiot now. XD Oh well, all part of the learning process I guess. Thanks! – bumbleshoot Jul 10 '12 at 00:31
  • In my case, it was that my page was expected to be pointing to something like: webroot/somedirectory/index.php but then by mistake it resulted writing on "somedirectory" as the PHP file (so the directory was actually not there). When the path above was fed to the browser, the PHP text was delivered... – David Ramirez Jun 09 '14 at 19:40