There is an html page:

<html> <head> <title> </title> </head> <body> <form action="processorder.php" method = "post"> <table border = "0"> <tr bgcolor ="#cccccc"> <td width="150">Product</td> <td width= "15">Quantity</td> </tr> <tr> <td>Tyres</td> <td align="center"><input type="text" name="tireqty" size="3" maxlength="3"></td> </tr> </tr> <td>Oil</td> <td align="center"><input type="text" name="oilqty" size="3" maxlength="3"></td> </tr> <tr> <td>spark plug</td> <td align="center"><input type="text" name="sparkqty" size="3" maxlength="3"></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="send order"/></td> </tr> </table> </form> </body> </html> 

Php file goes to it

 <html> <head> <title> Order result </title> </head> <body> <h1>auto parts</h1> <h2>order results</h2> <?php $tireqty=$_POST['tireqty']; $oilqty=$_POST['oilqty']; $sparkqty=$_POST['sparkqty']; echo "<p> order is processed at "; echo date('H:i, jS F Y'); echo '</p>'; echo '<p> Ordered: </p>'; echo $tireqty.' tires <br/>'; echo $oilqty.' oil bottles <br/>'; echo $sparkqty.' spark plugs <br/>'; ?> ?> </body> </html> 

When starting from a hosting, everything works, locally it gives an error:

Notice: Undefined offset: 1 in D: \ PHP \ second \ processorder.php on line 12

Notice: Undefined offset: 2 in D: \ PHP \ second \ processorder.php on line 13

Notice: Undefined offset: 3 in D: \ PHP \ second \ processorder.php on line 14

Actually, he sees a mistake here:

 $tireqty=$_POST['tireqty']; $oilqty=$_POST['oilqty']; $sparkqty=$_POST['sparkqty']; 

IDE - PhpStorm 2016.1 Web Server - XAMP

  • Because, on the hosting, the display of errors is turned off, I $_POST['tireqty'] , that’s not what is highlighted ... but this is not a mistake in principle, but a notification .... But it says that there is no such variable as $_POST['tireqty'] , $_POST['oilqty'] and the other from the post .... and all because. that at the time of creating the page they really do not ... and appear only when you send a post request ...... respectively, you need to check for existence ... $tireqty= isset($_POST['tireqty']) ? $_POST['tireqty'] : 'defaultValue' $tireqty= isset($_POST['tireqty']) ? $_POST['tireqty'] : 'defaultValue' and the rest also - Alexey Shimansky
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

These are remarks that the elements of the array are not initialized; most likely, these comments on the hosting are added to the log, so you don’t notice them. It is considered to be a good form to encode in such a way that they do not arise, since they indicate potentially dangerous sections of code that may later cause errors. At the time of the first launch of the script, you do not have data in the $_POST array, so it is not correct to use it, it would be good to include the form handler only if POST data is transferred, and check each used element for existence (for example, using the isset() ).

 <?php if(!empty($_POST)) { $tireqty = isset($_POST['tireqty']) ? $_POST['tireqty'] : ''; $oilqty = isset($_POST['oilqty']) ? $_POST['oilqty'] : ''; $sparkqty = isset($_POST['sparkqty']) ? $_POST['sparkqty'] : ''; echo "<p> order is processed at "; echo date('H:i, jS F Y'); echo '</p>'; echo '<p> Ordered: </p>'; echo $tireqty.' tires <br/>'; echo $oilqty.' oil bottles <br/>'; echo $sparkqty.' spark plugs <br/>'; } 
  • Specially checked on other machines, everything works. Made virtualka with Windows10, WebStorm, XAMP - the error is reproduced. - Polietaiev

Removed the current version of PhpStorm and set the 9th. Everything is working.