I have 2 php files, first.php and second.php. The job of both the PHP files are to write a string value to a text file called "newfile.txt".
ISSUE im facing: With the method shown below the second.php will overwrite whatever the first.php has written in the text file.
GOAL: I want to write the value outputted by first.php in the first line and value of second.Php in the second line of the same text file(ie newfile.txt ). So whatever First.php outputs, i would like to update the first line and whatever second.php outputs i would like to update it in the second line.
IMPORTANT NOTE: I dont want to create a new line. I want to update the line first.php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "LIGHTS TURNED ON";
fwrite($myfile, $txt);
fclose($myfile);
second.php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "LIGHTS TURNED OFF";
fwrite($myfile, $txt);
fclose($myfile);
Example of how intend newfile.txt to be
LIGHTS TURNED ON //update whatever first.php outputs
LIGHTS TURNED OFF //update whatever second.php outputs
Thank you so much for reading.