test - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of test.php

  1. <?php
  2.  
  3. ?>
  4.  
  5. <html>
  6.  
  7. <head><title>Elenco capi disponibili nei punti vendita</title></head>
  8.  
  9. <body>
  10.  
  11. <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  12.  
  13.     <p>
  14.  
  15.         Scegli il modello dall'elenco <br />
  16.  
  17.         <select name="modello">
  18.  
  19.             <?php
  20.  
  21.             // Comando SQL
  22.  
  23.             $strSQL = "SELECT DISTINCT CodModello FROM capi ORDER BY CodModello;";
  24.  
  25.             $risultato = mysql_query($strSQL);
  26.  
  27.             while($riga = mysql_fetch_array($risultato))
  28.  
  29.             {
  30.  
  31.                 echo "<option value=\"" . $riga["CodModello"] . "\">" . $riga["CodModello"]
  32.  
  33.                     . "</option> \n";
  34.  
  35.             }
  36.  
  37.             ?>
  38.  
  39.         </select>
  40.  
  41.     </p>
  42.  
  43.     <p>
  44.  
  45.         Scegli la taglia dall'elenco <br />
  46.  
  47.         <select name="taglia">
  48.  
  49.             <?php
  50.  
  51.             // Comando SQL
  52.  
  53.             $strSQL = "SELECT DISTINCT Taglia FROM capi ORDER BY Taglia;";
  54.  
  55.             $risultato = mysql_query($strSQL);
  56.  
  57.             while($riga = mysql_fetch_array($risultato))
  58.  
  59.             {
  60.  
  61.                 echo "<option value=\"" . $riga["Taglia"] . "\">" . $riga["Taglia"]
  62.  
  63.                     . "</option> \n";
  64.  
  65.             }
  66.  
  67.             ?>
  68.  
  69.         </select>
  70.  
  71.     </p>
  72.  
  73.     <input type="submit" name="invio" value="Cerca" />
  74.  
  75.     <input type="submit" name="aggiorna" value="Aggiorna" />
  76.  
  77. </form>
  78.  
  79. <?php
  80.  
  81. if(isset($_POST['aggiorna'])) {
  82.  
  83.     header("Location: " . $_SERVER['PHP_SELF'] );
  84.  
  85. }
  86.  
  87.  
  88.  
  89. if(isset($_POST['invio'])) {
  90.  
  91. // acquisisce modello e taglia dal form HTML
  92.  
  93. $modello = $_POST["modello"];
  94.  
  95. $taglia = $_POST["taglia"];
  96.  
  97. echo "<h2>Elenco dei capi disponibili per ciascun punto vendita</h2> \n";
  98.  
  99. // Comando SQL
  100.  
  101. $strSQL = "SELECT PuntoVendita, ID, Taglia, Colore, CodModello FROM capi ";
  102.  
  103. $strSQL .= "WHERE CodModello = $modello AND Taglia = '$taglia' ";
  104.  
  105. $strSQL .= "ORDER BY PuntoVendita";
  106.  
  107. $risultato = mysql_query($strSQL);
  108.  
  109. ?>
  110.  
  111. <!-- intestazione della tabella -->
  112.  
  113. <table border=1>
  114.  
  115.     <tr>
  116.  
  117.         <th>Punto vendita</th>
  118.  
  119.         <th>Codice capo</th>
  120.  
  121.         <th>Taglia</th>
  122.  
  123.         <th>Colore</th>
  124.  
  125.         <th>Modello</th>
  126.  
  127.     </tr>
  128.  
  129.     <?php
  130.  
  131.     while($riga = mysql_fetch_array($risultato))
  132.  
  133.     {
  134.  
  135. // Operazioni sulla riga
  136.  
  137.         echo "<tr> \n";
  138.  
  139.         echo "<td>" . $riga["PuntoVendita"] . "</td> \n";
  140.  
  141.         echo "<td>" . $riga["ID"] . "</td> \n";
  142.  
  143.         echo "<td>" . $riga["Taglia"] . "</td> \n";
  144.  
  145.         echo "<td>" . $riga["Colore"] . "</td> \n";
  146.  
  147.         echo "<td>" . $riga["CodModello"] . "</td> \n";
  148.  
  149.         echo "</tr> \n";
  150.  
  151.     } //fine while
  152.  
  153.     } //fine isset
  154.  
  155.     ?>
  156.  
  157. </table>
  158.  
  159. </body>
  160.  
  161. </html>
  162.  
  163.  
  164.  
File Description
  • test
  • PHP Code
  • 05 Jun-2023
  • 2.53 Kb
You can Share it: