Results 1 to 7 of 7

Thread: [RESOLVED] Notice: Undefined index: submit

  1. #1

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Resolved [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
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Notice: Undefined index: submit

    PHP Code:
    if (!isset($_POST['submit']))      //this is line 11 


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    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
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Notice: Undefined index: submit

    use <?php rather than <?=. The latter is deprecated.

  5. #5

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    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
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  6. #6
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    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.

  7. #7

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    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
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width