Basic PHP setup problem: only the root PHP script works

Hi, I am new to PHP and just setup PHP as per ‘Build your own …using PHP&MYSQL’. I have set up the wamp server and it shows all the information including PHP.ini and connects to MYSQL as well. I am placing my scripts in the www directory as shown by admin. The PHP instructions in the first script works but any PHP instructions in the html/included scripts are not doing anything. Can some one tell what may be the problem?

Can you give a little more information about how you are including the scripts? How do the including and included scripts look like?

The problem might be in the way you’re providing the path to include() or maybe you’re not placing PHP code tags correctly.

A simple script like below does only the html part:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Form Example</title>
        <meta http-equiv="content-type"
                content="text/html; charset=utf-8"/>
    </head>
    <body>
        <p>  The name given are 
            <?php
            echo 'testing';
            ?>
        </p>
    </body>
</html>
where as the script below works:
<?php
$pageContents = <<< EOPAGE
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html lang="en" xml:lang="en">
<head>

        <title>Today date</title>
        <meta http-equiv="content-type"
                content="text/html;"/>
    </head>
    <body>    
        <p>  The date is
EOPAGE;
$pageContents2 = <<< EOPAGE
            
            
        </p>
    </body>
</html>
EOPAGE;

echo $pageContents ;
echo date('l,F dS Y.') ;
echo $pageContents2;
?>

It’s weird that PHP code is not executing. Which enviroment are you using to execute your scripts? Did you install PHP and MySQL separately and built your own wamp or are you using WampServer?

I’ve used EasyPHP and I haven’t had any problems yet.

I have installed wamp server directly in windows xp environment. Some how the second level is not able to recognize PHP tags

I don’t have WampServer installed in my laptop but in my individual installation of PHP, Apache, MySQL the following does work quite well:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title>Form Example</title>
	<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</head>
<body>
<p> The name given are 
<?php echo 'testing'; ?>
</p>
where as the script below works:
<?php
$pageContents = <<< EOPAGE
<p> The date is
EOPAGE;
$pageContents2 = <<< EOPAGE
</p>
EOPAGE;

echo $pageContents ;
echo date('l,F dS Y.') ;
echo $pageContents2;
?>
</body>
</html>

Outputs:


The name given are testing
where as the script below works:

The date isThursday,January 05th 2012.

BTW why you have html,body tags in the strings in heredoc ?