-2

I just downloaded mamp 3 with php 5.5.10. I created a new file with just php and put in the htdocs folder and it displayed correctly in chrome. But then I added some html and it displayed nothing. I checked the source code and it had one blank line. How do I fix it so that it displays the HTML and PHP? Also, why does this happen?

initial php was

<?php echo 'hi';?>

then i changed it to

<!DOCTYPE html>
<html>
<head>
<title>food</title>
</head>
<body>
<?php 
echo 'hi';
?>
<form method="post" <?php echo "action=\"$_SERVER['PHP_SELF']\"";?>>
<input type="text" name="food" placeholder="enter a food name">
<input type="submit" value="submit">
</form>
</body>
</html>
gnomenomy
  • 3
  • 2

2 Answers2

0

Answered here

Answer - obviously change php version to suit.

The solution is uncommenting lines in the php.ini file which can be found in /MAMP/Directory/bin/php/php5.5.3/conf/php.ini

Comment out Opcache:

[OPcache]
;zend_extension="/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/opcache.so"
;  opcache.memory_consumption=128
;  opcache.interned_strings_buffer=8
;  opcache.max_accelerated_files=4000
;  opcache.revalidate_freq=60
;  opcache.fast_shutdown=1
;  opcache.enable_cli=1

Documentation (yes it started in 5.5):

http://www.php.net/manual/en/intro.opcache.php

Community
  • 1
  • 1
misterManSam
  • 24,303
  • 11
  • 69
  • 89
0

This line is goofy:

<form method="post" <?php echo "action=\"$_SERVER['PHP_SELF']\"";?>>

change it to:

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">

Chances are you just don't have error reporting turned on. Otherwise you'd see this:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /Applications/MAMP/htdocs/test/index.php on line 10

Turn on error reporting:

Open up /Applications/MAMP/bin/php/{your PHP version}/conf/php.ini.

Find display_errors = Off (around line 277) and change it to display_errors = On.

Restart MAMP.

borrowed error reporting instructions form here: http://gilbert.pellegrom.me/enable-php-error-reporting-in-mamp/

Kai Qing
  • 18,793
  • 5
  • 39
  • 57