php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18215 Notice: Undefined variable: submit in C:\
Submitted: 2002-07-07 18:41 UTC Modified: 2002-07-09 13:56 UTC
From: orraco at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.2.1 OS: Win2000
Private report: No CVE-ID: None
 [2002-07-07 18:41 UTC] orraco at hotmail dot com
Although new to PHP I have been testing a few web Utilities.
I have downloaded some'code that provides a ping function. I have tested my PHP install to the best of my knowledge its correct but still recieve an error Notice: Undefined variable: submit in C:\Documents and Settings\Administrator\My Documents\My Webs\php-ping.php on line 14
I have been testing on a local machine running Windows NT 5.0 build 2195 and Microsoft-IIS/5.0 the code is as follows

<?php
//  This script was writen by webmaster@theworldsend.net, Aug. 2001
//  http://www.theworldsend.net 
//  This is my first script. Enjoy.
//  
// Put it into whatever directory and call it. That's all.
//
//-------------------------
$max_count = "10"; //maximum count for ping command
$os = "win";   // win or unix (unix means all flavors of linux as well)
// -------------------------
//
// nothing more to be done. 
If ($submit == "Ping!") {
  If ($count > $max_count) 
  {
     echo 'Maximum for count is '.$max_count;
     echo '<a href="php-ping.php">Back</a>';
     $again = True;
  }
  else 
  {
     If (ereg(" ",$host))  
     {
          echo 'No Space in Host field allowed !';
          echo '<a href="php-ping.php">Back</a>';
          $again= True;
     }
     else 
     {
          echo("Ping Output:<br>"); 
          echo("<pre>");
          $host = escapeshellarg($host); 
          $count = escapeshellarg($count);
          if ($os =="win") 
          {
             system("ping -n $count $host", $list);
          }
          else
          {
             system("ping -t $count $host", $list);
          }; 
          echo("</pre>");
      }
   }
} 
else 
{
  echo '
  <html><body>
  <form methode="post" action="php-ping.php">
  Enter IP or Host <input type="text" name="host"></input>


  Enter Count <input type="text" name="count" size="2" value="4"></input>
  <input type="submit" name="submit" value="Ping!"></input>
  </form>
  </body></html>';
}
?>	

Please can you help I have tried all that I can think of. I can remove the error message via php.ini but would like it to work and return a value.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-07 18:44 UTC] jan@php.net
In PHP 4.2.0, the 'register_globals' setting default changed to
be off. See http://www.php.net/release_4_2_0.php for more info.
We are sorry about the inconvenience, but this change was a necessary
part of our efforts to make PHP scripting more secure and portable.
 [2002-07-08 03:52 UTC] orraco at hotmail dot com
I have already tried the 'register_globals' setting although I have read that it is set this way for a reason in other articles. I notice from looking around that other people are having similar errors, and are having great difficulty in finding a solution.

But even with the change I don't get an output..... Any ideas??
 [2002-07-09 10:46 UTC] orraco at hotmail dot com
Anyone help with this ?
 [2002-07-09 13:56 UTC] philip@php.net
You have register_globals enabled and $submit may exist if the form is submitted (although not all browsers/situations pass the submit button, like sometimes when pressing enter).  Anyway, use a check like isset() otherwise an error of level E_NOTICE is created if a variable doesn't exist.  Example:

print $undefined;        // E_NOTICE error
if ($undefined)          // E_NOTICE error
if (isset($undefined)) { // No E_NOTICE error

I would suggest putting something like the following in your code:
 <input type="hidden" name="action" value="form_submitted"> 
See also: error_reporting(), empty() and error handling.
Am adding a faq on this now.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 10:00:01 2026 UTC