Search code examples
phpmamp

How do I update the source code with mamp?


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>

Solution

  • 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/