I tried to create a form-site, where the entries are getting saved in a CSV and im getting back to my index.php when the submit Button is pushed, but I dont know where i went wrong, because when i push the button, the site simply reloads without doing anything.
Thanks for the Help.
<body>
<div class="page-header">
<h1>CSV Datei Formular</h1>
</div>
<?php
function beschreibeCSV($w1,$w2,$w3,$w4,$w5){
$daten = array($w1, $w2, $w3, $w4, $w5);
$fp = fopen('kontaktliste.csv', 'a');
fputcsv($fp, $daten);
fclose($fp);
}
if(isset($_Post['submit'])){
$w1 = $_Post['vorname'];
$w2 = $_Post['nachname'];
$w3 = $_Post['tel'];
$w4 = $_Post['adresse'];
$w5 = $_Post['plz'];
beschreibeCSV($w1,$w2,$w3,$w4,$w5);
header("Location: ../index.php");
exit;
}
?>
<div>
<form class="form-horizontal" method="Post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<fieldset>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Vorname</label>
<div class="col-md-4">
<input id="textinput" name="vorname" type="text" placeholder="Vorname" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Nachname</label>
<div class="col-md-4">
<input id="textinput" name="nachname" type="text" placeholder="Nachname" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Tel</label>
<div class="col-md-4">
<input id="textinput" name="tel" type="text" placeholder="Tel" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Adresse</label>
<div class="col-md-4">
<input id="textinput" name="adresse" type="text" placeholder="Straße Hausnummer" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">PLZ</label>
<div class="col-md-4">
<input id="textinput" name="plz" type="text" placeholder="PLZ" class="form-control input-md" required="">
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="singlebutton">Add to CSV</label>
<div class="col-md-4">
<button id="singlebutton" type="submit" name="submit" class="btn btn-primary">Save</button>
</div>
</div>
</fieldset>
</form>
</div>
</body>