|
-
Apr 22nd, 2008, 02:47 AM
#1
[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
-
Apr 22nd, 2008, 05:18 AM
#2
-
Apr 22nd, 2008, 08:31 AM
#3
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:
http://localhost:8080/<?=$_SERVER['PHP_SELF']?>
Here's the browser error message:
Im using IE 6.0 anyway...
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
-
Apr 22nd, 2008, 08:34 AM
#4
Re: Notice: Undefined index: submit
use <?php rather than <?=. The latter is deprecated.
-
Apr 22nd, 2008, 08:45 AM
#5
Re: Notice: Undefined index: submit
Thanks guys..It worked..
Here's the modified snippet:
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
-
Apr 22nd, 2008, 09:06 PM
#6
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)...
Has someone helped you? Then you can Rate their helpful post. 
-
Apr 23rd, 2008, 02:20 AM
#7
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|