使用php

时间:2015-12-12 14:47:50

标签: php csv

我尝试创建一个表单站点,其中条目以CSV格式保存,并且当按下提交按钮时我回到我的index.php,但我不知道我哪里出错了,因为我推的时候按钮,网站只是重新加载而不做任何事情。

感谢您的帮助。

<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>

1 个答案:

答案 0 :(得分:1)

改为使用$_Post - &gt; $_POST所有大写字母,请查看此处的文档以获取更多信息 - http://php.net/manual/en/language.variables.superglobals.php