Reputation: 5
I have setup a form to allow people to submit accounts to my account generator but I have a couple problems:
Old entries get deleted when new one is made
Entries are displayed 2 times in the file
below I have included my code please help me
<?php
$file = fopen("collections/mc.txt", "w") or die("Unable to open file!");
if (isset($_POST['nfa'])) {
$type = "nfa";
}
if (isset ($_POST['sfa'])) {
$type = "sfa";
}
if (isset ($_POST['ufa'])) {
$type = "ufa";
}
if (isset ($_POST['unknown'])) {
$type = "unknown";
}
$username = $_POST['email'];
$password = $_POST['password'];
$mailurl = $_POST['accessurl'];
$mailpassword= $_POST['accesspassword'];
$details = "
==================================
type: $type
email: $username
password: $password
mail url: $mailurl
mail password: $mailpassword
==================================
";
fwrite($file, $details);
$details = "
==================================
type: $type
email: $username
password: $password
mail url: $mailurl
mail password: $mailpassword
==================================
";
fwrite($file, $details);
fclose($file);
?>
<a href="/mc.php">Go Back</a>
Upvotes: 0
Views: 37
Reputation: 136
This should work:
<?php
if (isset($_POST['nfa'])) {
$type = "nfa";
}
if (isset ($_POST['sfa'])) {
$type = "sfa";
}
if (isset ($_POST['ufa'])) {
$type = "ufa";
}
if (isset ($_POST['unknown'])) {
$type = "unknown";
}
$username = $_POST['email'];
$password = $_POST['password'];
$mailurl = $_POST['accessurl'];
$mailpassword= $_POST['accesspassword'];
$details = "
==================================
type: $type
email: $username
password: $password
mail url: $mailurl
mail password: $mailpassword
==================================
";
file_put_contents("collections/mc.txt", $details, FILE_APPEND);
?>
<a href="/mc.php">Go Back</a>
Upvotes: 1