esto te puede ayudar creo que es lo que estas buscando 
 
este es el codi HTML...  
Código:
  <table >
      <caption> <b class="centro">Pedido de libros</b> </caption>
      <hr>
      <tr class="negra"><!-- Esto te da color al Titulo de la tabla-->
         <th>Libros</th>
         <th>Cantidad</th>
      </tr><!--  fin de class-->
      <form action="compra.php"method="post">
      <tr>
         <td>Historia</td>
         <td><input type="text" name="Historia" size="6"></td>
      </tr>
      <tr>
         <td>Matematica</td>
         <td><input type="text" name="Matematica" size="6"></td>
      </tr>
      <tr>
         <td>Castellano</td>
         <td><input type="text" name="Castellano" size="6"></td>
      </tr>
      <tr>
         <td>Deporte</td>
         <td><input type="text" name="Deporte" size="6"></td>
      </tr>
      <tr>
         <td><input type="submit" name="enviar" value="Comprar"></td>
         <td><input type="reset" name="borrar" value="Borrar"></td>
      </tr>
      </form>
   </table>
  y este el php  
 Código PHP:
    <?php
echo'<h2>Compra de productos</h2>';
 
echo 'Su compra fue realizada el dia ';
echo date('j ');  // En este bloque muesta el dia, mes, hora y año
echo ' de '.date('F');
echo ' a las ';
echo date('H:i');
echo ' del año ';
echo date('Y').'</br>';// Fin del bloque que muestra dia, mes, hora y año
 
 
echo'<table>';
 
   echo '<h4>Libros a comprar</h4>';
   echo'<tr>';
      echo'<td>'.'Historia:'.'</td>';
      echo'<td>'.$Historia.'</td>';
   echo'</tr>';
   echo'<tr>';
      echo'<td>'.'Matematica: '.'</td>';
      echo'<td>'.$Matematica.'</td>';
   echo'</tr>';
   echo'<tr>';
      echo'<td>'.'Castellano: '.'</td>';
      echo'<td>'.$Castellano.'</td>';
   echo'</tr>';
   echo'<tr>';
      echo'<td>'.'Deporte: '.'</td>';
      echo'<td>'.$Deporte.'</td>'.'</br>';
   echo'</td>';
 
echo'</table>';
 
 
define('CASTELLANO','10');
define('HISTORIA','15.4');
define('MATEMATICA','5');
define('DEPORTE','20.3'); 
 
$total= 0.00;
$subtotal = 0.00;
$iva = 0.10;
 
$subtotal = $Historia * HISTORIA + 
         $Matematica * MATEMATICA +
         $Deporte * DEPORTE +
         $Castellano * CASTELLANO;
 
echo '</br>';
 
$total = number_format($total,2,".", " ");
echo 'Sub-Total: '.$subtotal;
 
echo '</br>';
 
$total = ($subtotal * $iva) + $subtotal;
echo 'El monto a cancelar es: '.$total;
echo'</br>';
 
// Se crea un archivo TXT y se copian los datos en el
 
$stringsalida = $Historia."Historia\t". $Deporte."Deporte\t". $total."\t"."\n";
 
// Crear archivo txt
@ $fp = fopen('pedido.txt','a');
   @flock($fp,2);
 
   if(!$fp)
   {
      echo'<p><strong> Su orden no ha podido ser procesada en este momento</p></strong>';
      exit;
   }
 
   fwrite($fp, $stringsalida);
   flock($fp,3);
   fclose($fp);
 
   echo'<p> Su orden ha sido recibida y guardada.</p>';
 
?>    
  el codigo esta un poco enredado pero funciona  
