PHP is parsing incorrectly on LAMP server.

I’m using the most PHP with apache 2.2.22, and the LAMP stack. I have a site folder defined on my desktop named “root” which stores the site, and all of the pages in the site are read correctly.

My problem is that when I am using PHP, it is only allowing simple commands for some reason (such as echo, defining variables, adding, subtracting, etc) and not anything more advanced. I’m really confused, because it seems to be parsing basic commands, so I don’t believe PHP is installed incorrectly. Is there some configuration that I must change for it to work? Does the server have permission to run advanced PHP commands?

I hope someone can help, really stumped here. I’m somewhat of a beginner to PHP, so please forgive me if the fix is obvious. Thank you!

Make sure you have error reporting on

You can do this by adding this to the beginning of your script
[php]error_reporting(E_iALL);
ni_set(‘display_errors’,‘1’);[/php]

If you still get nothing please add the code of a file that is not working as it should.

Thanks for helping JimL. I’m relatively new to PHP so I have not done too much yet, but I have tried to put together this small PHP segment for storing clientside text for comments in my site.

This is what I have thus far. The error reporting didn’t seem to have any effect.

[php]

<?php error_reporting(E_iALL); ni_set('display_errors','1'); if($_POST) { $name = $_POST["name"]; $post = $_POST["post"]; $comment="

$name said:
"$post"

"; $handle = fopen("comments.html","a"); fwrite($handle,"$comment"); fclose($handle); } ?>

[/php]

If I enter a name but not a comment, it tells me “You must enter a name.” and if I enter a comment but not a name, it tells me “You must enter a name.” This leads me to believe that the PHP is reading… but not exactly the way it should be. I have a few basic test PHP’s that do addition, subtraction, and so on; those work fine.

Hm, you don’t have any validation like that in your php file, do you have any javascript handling the form?

Sorry, my bad, I forgot the external PHP file being referenced by the form. The internal part might not currently be used… I gave up on this project a while ago. I’m just posting it as an example of my difficulties, as I don’t seem to be able to write anything of use without it ceasing to run. All of the error checking did not seem to work so far.

This is what I have in my “comments.php,” which is a file referenced by the HTML form on the page which includes a name and comment text box:

[php]<?php
error_reporting(E_iALL);
ni_set(‘display_errors’,‘1’);
$name = $_POST[“name”];
$post = $_POST[“post”];
$comment="

$name said:
$post

";

if ($name == “”)
{
die(“You must enter a name.”);
}
elseif ($post == “”)
{
die(“You must enter a comment.”);
}
else
{
$h = fopen(“comments.html”,“a”);
fwrite($h,"$comment");
fclose($h);
header(“Location: index.html”);
}

?>
[/php]

Again it seems like the error checking code you gave me does not seem to work here. In fact, when I added the error checking the code did not work at all. It does not run the kill arguments for leaving the name and comment fields blank.

Something strange has happened when I copied the error reporting stuff, it should be like this:
[php]error_reporting(E_ALL);
ini_set(‘display_errors’,‘1’);[/php]

[hr]

This works fine here:

[php]


<?php error_reporting(E_ALL); ini_set('display_errors','1'); $name = $_POST["name"]; $post = $_POST["post"]; $comment="

$name said:
$post

"; if ($name == "") { die("You must enter a name."); } elseif ($post == "") { die("You must enter a comment."); } else { die($comment); }[/php]

I tried your copy of the code which you say works, but it seems like the PHP still isn’t reading quite right. Would you like to look at the page as displayed on my site? Perhaps you will see what is wrong. If you are OK with that, I can message you the site (it is more of a personal site so I’d rather not have the URL go flying around publicly).

Since you say the code works, I suppose it is not necessarily my coding that is the problem. I’m guessing that there is some configuration that is not correct on my site, but I’ve looked into it and haven’t found any fixes yet.

Sorry, I’ve had a busy week. I still would appreciate help if possible on PHP. I need to fix my site so that PHP code can be executed. I feel like a lot of it is disabled, but I do not know where this configuration would be.

Sponsor our Newsletter | Privacy Policy | Terms of Service