因此,一开始,我一般对编程还是比较陌生的,所以请原谅。我正在尝试将表单输入存储在JSON文件中。但是我得到了
解析错误:语法错误,意外的'$ json'是我缺少分号,还是我的代码结构有问题,还是我完全缺少部分内容?
<?php
if ( !empty ($_POST) ) {
//Convert data to JSON
$PostArray = array (
"Voornaam" => $_POST['Voornaam'],
"Achternaam" => $_POST['Achternaam'],
"Adres" => $_POST['Adres'],
"Postcode" => $_POST['Postcode'],
"Woonplaats" => $_POST['Woonplaats'],
"BSN" => $_POST['BSN'],
"Geboortedatum" => $_POST['Geboortedatum']
)
$json = json_encode( $PostArray );
//Checken voor errors.
if (json_last_error()) {
exit("We have an error")
}
$file = 'registratie.json';
//Write to file
file_put_contents( $file, $json, FILE_APPEND);
}
?>
<html>
<head>
<meta charset="utf-8">
<title>Bronnen</title>
<meta name="Marco" content="">
<meta name="Bronnen- Form" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSS stylesheet-->
<link href="assets/CSS/placeholder.css" rel="stylesheet">
</head>
<body>
<div class="container">
<form action="index.php" method="post">
<fieldset>
<div class="Form-Group">
<label for="Voornaam">Voornaam:</label><br>
<input type="text" class="Form-Control" name="Voornaam"><br>
</div>
<div class="Form-Group">
<label for="Achternaam">Achternaam:</label><br>
<input type="text" class="Form-Control" name="Achternaam"><br>
</div>
<div class="Form-Group">
<label for="Adres">Adres:</label><br>
<input type="text" class="Form-Control" name="Adres"><br>
</div>
<div class="Form-Group">
<label for="Postcode">Postcode:</label><br>
<input type="text" class="Form-Control" name="Postcode"><br>
</div>
<div class="Form-Group">
<label for="Woonplaats">Woonplaats:</label><br>
<input type="text" class="Form-Control" name="Woonplaats"><br>
</div>
<div class="Form-Group">
<label for="BSN">BSN:</label><br>
<input type="number" class="Form-Control" name="BSN"><br>
</div>
<div class="Form-Group">
<label for="Geboortedatum">Geboortedatum:</label><br>
<input type="date" name="Geboortedatum" id="datepicker"><br><br>
<div class="Sumbit-button">
<input type="submit" value="Submit" class="Submit" name="ok">
</div>
</div>
</fieldset>
</form>
</div>
</body>
</html>