HTML :
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>test</title>
<link rel="stylesheet" href="style.css?v=2">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
</head>
<body>
<div class="wrapper">
<div class="search-input">
<form method="post" action="store.php">
<input type="text" placeholder="Type to search..">
<input type="submit" value="Done"/>
<div class="autocom-box">
<!-- here list are inserted from javascript -->
</div>
<div class="icon"><i class="fas fa-search"></i></div>
</div>
</div>
<script src="suggestions.js?v=3"></script>
<script src="js/script.js?v=2"></script>
</body>
</html>
suggestion.js
let suggestions = [
"YouTube",
"YouTuber",
"YouTube Channel",
"Blogger",
];
I need that when the user writes something to the input so that the data is saved and written to json but I don't know how it didn't work for me via php, so I would need help with how to do it in json
store.php
<?php
$myfile = fopen("suggestions.js", "a+");
$txt = "Login name : ".$_POST['name'].;
fwrite($myfile, $txt); fclose($myfile);
?>
$jsonFile = '/path/to/your/json/suggestion.js';
$data = (file_exists($jsonFile))
? json_decode(preg_replace('#^let suggestions = \[(.+)\];\s*$#', '$1', file_get_contents($jsonFile)))
: [];
$data[] = $_POST['name'];
file_put_contents($jsonFile, 'let suggestions = ' . json_encode($data) . ';');