-1

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>
D.Low
  • 1

1 Answers1

1

Use instead $_Post -> $_POST all uppercase letters, check documentation here for more info - http://php.net/manual/en/language.variables.superglobals.php

Armen
  • 4,064
  • 2
  • 23
  • 40
  • thanks, now it works...never thougt about it. – D.Low Dec 12 '15 at 15:04
  • Yes all variables like $_GET, $_SERVER. $_SESSION ... should be used in uppercase way, if answer was helpful don't forget to accept it – Armen Dec 12 '15 at 15:12
  • 1
    *"Try using"* answers are not very informative as to the exact reason why their code failed. There is a "reason" and you didn't give it. – Funk Forty Niner Dec 12 '15 at 15:20
  • @Fred-ii- but isn't answer helpful ? and solved issue ? – Armen Dec 12 '15 at 15:25
  • 1) helpful, yes and no. 2) solved issue yes, but.. you left out the reason why it failed. There is documentation on this on the PHP.net website. You need to think about future visitors to the question/answer and the OP also. If they don't know it failed, then they would not have learned anything ;-) – Funk Forty Niner Dec 12 '15 at 15:33
  • @Fred-ii- it is not so easy always provide documentation reference, as it is time taking operation, but yes i agree it useful, i updated my answer – Armen Dec 12 '15 at 15:46