Hi all have this two files ,how do i use this file() function in my code to output the saved content of the file to the screen?
index.php :

<html> <head> <meta charset="windows-1252"> <title></title> </head> <body> <form action="processorder.php" method="post" > <table> <tr> <th>Item</th> <th></th> <th>Quantity</th> </tr> <tr> <td>Tires</td> <td></td> <td><input type="text" name ="tires"></td> </tr> <tr> <td>Oil</td> <td></td> <td><input type="text" name ="oil"></td> </tr> <tr> <td>Spark Plugs</td> <td></td> <td><input type="text" name ="plugs"></td> </tr> <tr> <td>Shipping address</td> <td></td> <td><input type="text" name ="address"></td> </tr> <tr> <td><input type ="submit"value="Submit Order" id="submit" name='submit' ></td> </tr> </table> </form> <?php
        if(isset($_POST['submit']))
        {

            $tires =($_POST['tires']);
            $plugs =($_POST['plugs']);
            $address =($_POST['address']);
            $oil=($_POST['oil']);



        }
        ?> </body> </html>

processorder.php :

<?php

$txt = "data.txt"; 
@$fh = fopen($txt, 'ab'); 
flock($fh,LOCK_EX);
if (isset($_POST['tires']) && isset($_POST['oil'])&& isset($_POST['plugs'])&& isset($_POST['address'])) 
    { // check if both fields are set
   $txt='Tires:'.' '.$_POST['tires']. '  ' .'Oil:'.' '.$_POST['oil'].' '.'Plugs:'.' '.$_POST['plugs'].' '.'Address'.' '.$_POST['address']; 

   $lines = file('data.txt');
   foreach ($lines as $value) {
       echo "$value";

   file_put_contents('data.txt',$txt."\n",FILE_APPEND); // log to data.txt 

   }

}
if (!$fh)
{
 echo '<p><strong> Your order could not be processed at this time. '
 .'Please try again later.</strong></p></body></html>';
 exit;
}
    fwrite(@$fh,$txt,  strlen($txt)); // Write information to the file
    fclose(@$fh); // Close the file
Member Avatar for diafol

You can output file contents easily with echo file_get_contents($filename);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.