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 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 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:
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!
You've written your first PHP program, but when you go to run it, all you see in your browser is the code—the program doesn't actually run. When this happens, the most common cause is that you are trying to run PHP somewhere that doesn't support PHP.
It might be PHP is not enabled in your apache configuration. You can uncomment PHP module by removing '#' sign at the beginning from httpd. conf file. Save file and then restart the web server.
Make sure your file has the . php extension on it, or whichever extension specified in the MIME definition in point #3, otherwise it will not be executed as PHP. Make sure you are not using short tags in the PHP file ( <? ), these are not enabled on all servers by default and their use is discouraged.
When PHP receives the file it reads through it and executes any PHP code it can find. After it is done with the file, the PHP interpreter gives the output of the code, if any, back to Apache. When Apache gets the output back from PHP, it sends that output back to a browser which renders it to the screen.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With