|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 10:00:01 2026 UTC |
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.