PDA

Click to See Complete Forum and Search --> : [RESOLVED] Notice: Undefined index: submit


KGComputers
Apr 22nd, 2008, 03:47 AM
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

<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:)

manavo11
Apr 22nd, 2008, 06:18 AM
if (!isset($_POST['submit'])) //this is line 11

KGComputers
Apr 22nd, 2008, 09:31 AM
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 http://localhost:8080/mergeforms.php, this produced an error.

and this statement http://localhost:8080/mergeforms.php 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

penagate
Apr 22nd, 2008, 09:34 AM
use <?php rather than <?=. The latter is deprecated.

KGComputers
Apr 22nd, 2008, 09:45 AM
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

manavo11
Apr 22nd, 2008, 10:06 PM
I actually think it should be:

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

and not:

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

if you look at the produced HTML, you probably get:

<form action="" method="post">

which works exactly the same way (empty action links back to the same page by posting the data)...

KGComputers
Apr 23rd, 2008, 03:20 AM
Manavo, thanks for the tip....:)

I also viewed the source in the IE and verified it as you suggested...Yes, your correct...:)

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 :)