when i run index.php in localhost giving below error : Notice: Undefined index: submit in C:\Program Files\EasyPHP 2.0b1\www\index.php on line 8 when i click on button "select" also giving error about authorization i have attached the error screens as jpg files. <html> <head> </head> <body> <?php if (!$_POST['submit']) { ?> Select from the items below: <br /> <form action="<?=$_SERVER['PHP_SELF']?>" method="POST"> <select name="options[]" multiple> <option value="power steering">Power steering</option> <option value="rear wiper">Rear windshield wiper</option> <option value="cd changer">6 CD changer</option> <option value="fog lamps">Fog lamps</option> <option value="central locking">Central locking</option> <option value="onboard navigation">Computer-based navigation</option> </select> <input type="submit" name="submit" value="Select"> </form> <?php } else { if (is_array($_POST['options'])) { echo 'Here is your selection: <br />'; foreach ($_POST['options'] as $o) { echo "<i>$o</i><br />"; } } else { echo 'Nothing selected'; } } ?> </body> </html> warm regards, mk.
This is lazy coding. It should be: if (!isset($_POST['submit'])) PHP: Or: if (!empty($_POST['submit'])) PHP: (Both usually work, but it depends on the case which is most appropriate) However, this means your error reporting is not set to it's default. Open your php.ini file and change the value in error_reporting to: error_reporting = E_ALL & ~E_NOTICE Code (markup): Usually these notices are not shown by default, but it's a good practice to code in a way that they don't occur, because it slows down your performance.
<?=$_SERVER['PHP_SELF']?> PHP: change to <?php echo $_SERVER['PHP_SELF'];?> PHP: I see that on your host short php tags are disabled
thank you very much. your code : working perfect. if (!isset($_POST['submit'])) "<?php echo $_SERVER['PHP_SELF'];?>" i am new in PHP. i have started learning PHP today only. warm regards, mk.