I'm trying to add elements to an array after typing their name, but for some reason when I do
<?php
session_start();
$u = array("billy\n", "tyson\n", "sanders\n");
serialize($u);
file_put_contents('pass.txt', $u);
if (isset($_POST['set'])) {
unserialize($u);
array_push($u, $_POST['check']);
file_put_contents('pass.txt', $u);
}
?>
<form action="index.php" method="post">
<input type="text" name="check"/><br>
<input type="submit" name="set" value="Add person"/><br>
<?php echo print_r($u); ?>
</form>
It puts it in the array, but when I do it again, it rewrites the previous written element. Does someone know how to fix this?