How to save form in two txt files html and php

Viewed 71

I'm trying to submit a form with two text inputs and trying to save the two inputs to two separated text files but without success. I'm able to save the two inputs in one file but I can't manage to slipt the inputs in two separate text files.

Heres what i've tried:

HTML form:

<form action="run.php" method="post">
    Link:<br><input type="text" name="linkisv" value=""><br>
    Email:<br><input type="text" name="emailisv" value=""><br>
    <input type="submit" id ="submitButton" value="Submit">
</form>

The PHP solution:

<?php
$linkisv = $_POST["linkisv"]; //You have to get the form data
$emailisv = $_POST["emailisv"];
$file = fopen('configurationSettings.txt', 'w+'); //Open your .txt file
ftruncate($file, 0); //Clear the file to 0bit
$content = $linkisv. PHP_EOL .$emailisv;
fwrite($file , $content); //Now lets write it in there
fclose($file ); //Finally close our .txt
die(header("Location: ".$_SERVER["HTTP_REFERER"]));?>
1 Answers

With this code:

<?php
$linkisv = $_POST["linkisv"]; //You have to get the form data
$emailisv = $_POST["emailisv"];

// SAVING FIRST FILE
$file = fopen('configurationSettings.txt', 'w+'); //Open your .txt file
ftruncate($file, 0); //Clear the file to 0bit
$content = $linkisv;
fwrite($file , $content); //Now lets write it in there
fclose($file); //Finally close our .txt

// SAVING SECOND FILE
$file = fopen('second_file_name.txt', 'w+'); //Open your .txt file
ftruncate($file, 0); //Clear the file to 0bit
$content = $emailisv;
fwrite($file , $content); //Now lets write it in there
fclose($file); //Finally close our .txt

// REDIRECT
die(header("Location: ".$_SERVER["HTTP_REFERER"]));?>
Related