Hi, I am working my way through a book titled "How to Do Everything with PHP & MYSQL" and I am having a problem. Part of one script I am looking at returns an error: here it is:

<html>
<head>
<title></title>
</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="columsn" type="text" size="4">
<input type="submit" name="submit" value="Draw Table">
</form>

<?php
}
else
{
?>

<?php

$rows = $_POST['rows'];

echo "You wanted" . $rows;

?>
<?php
}
?>
</body>
</html>

Forget the else section of the form - I have been playing with it. As I understand the script it checks if the form exists, if it doesn't it creates it, then once the form exists the else section is processed - the code suggested creates a table based on the user's form entries.

The form works fine - however, when I press submit the server returns an error

"Not Found

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

Can anybody help me to understand this better.

Many thanks,
Keith Hulse

www.clearandsimplewebdesign.co.uk

    Sounds like the short_tags directive has been disabled (as it should be). In other words, instead of:

    <?=$_SERVER['PHP_SELF']; ?>

    you should be doing:

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

    Also, other parts of your code use other deprecated behaviors, such as if(!$POST['submit']) and assigning a $POST value to a variable without first checking if it exists. In other words, I hope you didn't pay money for this book you're following! :p

      Thanks for that brad. I have tried what you suggested with the same results. I am using MAMP on my Macbook, but I have also tested the script by uploading to my ftp account (which I know uses PHP).

      As regards the book. 'HOw to do Everything with PHP 7 MYSQL' by Vikram Vaswani. This is the second book I have tried that has been found wanting by the experts on forums. I am serious about getting to grips with PHP so would you have any suggestions?

      Finally, an absurdly simple question - would you have the above script in a .php file or a .html file - don't laugh, I just thought I would ask.

        Hi, just a note to say following brad's advice this matter has been resolved.

        Many thanks,
        Keith Hulse

          Write a Reply...