[RESOLVED] Notice: Undefined index: submit
Hi guys,
Just started learning php here:
I encountered this error when i compiled/run (http://localhost:8080/howtodo/mergeforms.php) the code below:
Notice: Undefined index: submit in C:\Program Files\Apache Group\Apache2\htdocs\howtodo\mergeforms.php on line 11
filename: mergeforms.php
Code:
<html>
<body>
<?php
//if the "submit" variable does not exist
//form has not been submitted
//display initial page
if (!$_POST['submit']) //this is line 11
{
?>
<form action ="<?=$_SERVER['PHP_SELF']?>" method="post">
Enter a number:<input name="number" size = "5">
<input type="submit" name="submit" value="go">
</form>
<?php
}
else
{
$number = $_POST['number'];
if ($number > 0)
{
echo 'You entered a positive number';
}
elseif($number < 0)
{
echo 'You entered a negative number';
}
else
{
echo 'You entered a zero';
}
}
?>
</body>
</html>
Greg:)
Re: Notice: Undefined index: submit
PHP Code:
if (!isset($_POST['submit'])) //this is line 11
Re: Notice: Undefined index: submit
Manavo11,
Thanks for the tip...Though the syntax error was removed, I still got an error regarding the apache server.Port 80 is used for IIS. So i decided to use 8080 for the apache...
After I typed , this produced an error.
and this statement changed into this:
Quote:
http://localhost:8080/<?=$_SERVER['PHP_SELF']?>
Here's the browser error message:
Im using IE 6.0 anyway...
Quote:
Forbidden
You don't have permission to access /< on this server.
--------------------------------------------------------------------------------
Apache/2.0.58 (Win32) PHP/5.2.5 Server at localhost Port 8080
What are the settings that I have to modify? :)
Greg
Re: Notice: Undefined index: submit
use <?php rather than <?=. The latter is deprecated.
Re: Notice: Undefined index: submit
Thanks guys..It worked.. :) :)
Here's the modified snippet:
Quote:
if (!isset($_POST['submit']))
{
?>
<form action="<?php $_SERVER['PHP_SELF']?>" method="post">
Enter a number:<input name="number" size = "5">
<input type="submit" name="submit" value="go">
</form>
<?php
}
Greg
Re: [RESOLVED] Notice: Undefined index: submit
I actually think it should be:
PHP Code:
<?php echo $_SERVER['PHP_SELF']?>
and not:
PHP Code:
<?php $_SERVER['PHP_SELF']?>
if you look at the produced HTML, you probably get:
Code:
<form action="" method="post">
which works exactly the same way (empty action links back to the same page by posting the data)...
Re: [RESOLVED] Notice: Undefined index: submit
Manavo, thanks for the tip....:)
I also viewed the source in the IE and verified it as you suggested...Yes, your correct...:)
PHP Code:
if (!isset($_POST['submit']))
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
Enter a number:<input name="number" size = "5">
<input type="submit" name="submit" value="go">
</form>
<?php
}
Anyways, are there a list of deprecated functions in php4 which can't be applied in version 5? Manual or something in pdf/chm or other formats?
Greg :)