Hi all,

I know this isn't strictly MAMP - I'm trying to use the basic <?=$_SERVER['PHP_SELF']?> variable in the following script, or any script (copied them straight out of a book):

<html>
<head></head>
<body>
<?php
if (!$POST['submit'])
{
?>
<form method="post" action="<?=$
SERVER['PHP_SELF']?>">
Enter number of rows
<input name="rows" type="text" size="4">
and columns
<input name="columns" type="text" size="4">
<input type="submit" name="submit" value="Draw Table">
</form>
<?php
}
else
{
?>
<table border="1" cellspacing="5" cellpadding="0">
<?php
// set variables from form input
$rows = $POST['rows'];
$columns = $
POST['columns'];
// loop to create rows
for ($r = 1; $r <= $rows; $r++)
{
echo "<tr>";
// loop to create columns
for ($c = 1; $c <= $columns; $c++)
{
echo "<td>&nbsp;</td>\n";
}
echo "</tr>\n";
}
?>
</table>
<?php
}
?>
</body>
</html>

The first part of the program loads, with a small form asking for number of rows and columns, but when I fill it in and press submit I get:

Not Found

The requested URL /< was not found on this server.

Apache/1.3.33 Server at havelock.local Port 80

with http://localhost/%3C?=$_SERVER['PHP_SELF']?%3E in the URL bar.

This happens whatever I use around it. Anybody got any ideas? I have Apache 1.3.3 and the latest MySQL and PHP 5 builds running on a MacBook Pro 17" (1 previous to current model).

Thanks
Edd

    Use normal PHP tags. Short tags are not guaranteed to be on, and they can cause conflict with XML tags.

    <?php echo $_SERVER['PHP_SELF']; ?>

    Oh and next time please place PHP (and HTML interspersed with PHP) code in php forum bbcode tags.

      Hi There,

      No still didn't work - browser bar "http://localhost/%3C?php%20echo%20$_SERVER['PHP_SELF'];%20?%3E"

      and same Not Found message. Could it be a problem with how Apache is configured?

      Sorry - how do you do the BBcode thing?

      Thanks
      Edd

        eddjc wrote:

        Could it be a problem with how Apache is configured?

        Sounds very like. If you view the HTML source, do you see the raw PHP code? If so, that's your problem.

        Does this file have a .php extension? If so, Apache wasn't correctly configured to parse .php files via the PHP interpreter.

        eddjc wrote:

        Sorry - how do you do the BBcode thing?

        Simply surround your PHP code with the [PHP](code goes here)[/PHP] tags.

        Also, instead of code such as

        if (!$_SESSION['user']) {

        to check if a variable exists/has data, you should be using something like:

        if(!empty($_SESSION['user'])) {
        // -- OR --
        if(!isset($_SESSION['user'])) {

          Aha! I had .html as the suffix for the file - I changed it to .php and it worked fine! Thank you!
          And just to check:

          This should be in a code box

          Great. Thanks again!

          Edd

            Write a Reply...