Php isset&&!空的不起作用


Php isset && !empty dont work

这个例子做我想做的事对我来说很好。1.文件

  <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>php test </title>
</head>
<body>
    <?php
    if (isset($_POST['go'])&& !empty($_POST['vorname'])){

        echo " ".$_POST["vorname"];     
        echo " ".$_POST["nachname"];
                }
    else {   ?>
    <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
        <input type="text" name="vorname" />
        <input type="text" name="nachname" />
        <input type="submit" name="go" />
    </form>
    <?php } ?>

</body>

</html>

所以我在我的测试文件中尝试了相同的语法,就像我在学习atm时尝试了所有新的php内容一样。但无论是否设置了var"Vorname",它都根本不起作用——它一直在提交并显示php代码。但我想要的是,如果var"Vorname"为空,它应该再次向我显示形式。

第二个文件

    <div class="Mitte" style="text-align:left;" >
    <?php
        if(isset($_POST['Buchung'])&& !empty($_POST)) {
    ?>
    <h2> PhP Auswertung </h2>
    <?php   $Preis=0;
        $Anrede=$_POST['Anrede'];
        echo "Sehr geehreter ".$Anrede." ";

        $titel=$_POST['Titel'];
        echo "$titel";

        echo " ".$_POST['Vorname'];

        echo ' '.$_POST['Nachname'];
    ?>
    <br />
    <br />
    <?php
        echo "Ihre angegebene Adresse lautet: ";
    ?>
    <br />
    <?php
        echo 'Die Strasse : '.$_POST['Strasse'];
    ?>
    <br />
    <?php
        echo 'Die PLZ : '.$_POST['PLZ'];
    ?>
    <br />
    <?php
        echo 'Der Ort : '.$_POST['Ort'];
    ?>

    <br />
    <br />

    <?php
        echo 'Die E-mail Adresse : '.$_POST['E-mail'];
    ?>
    <br />
    <br />

    <?php
        echo "Ihre Reise Informationen: ";
    ?>
    <br/>
    <?php
        $Reise=$_POST['Reiseart'];
        echo "$Reise";
    ?>
    <br />

    <?php
        echo "Erwachsene und/oder Kinder ? <br>";
        foreach ($_POST["Reisende"] as $value ) {
        echo "$value<br>";              
                            }
    ?>
    <br />
    <?php
        echo "Gew&auml;hlte Extras:  <br>";
        foreach ($_POST['extras'] as $extra) {
        echo "$extra<br>";
        if ($extra=="Mietwagen"){
        $Preis=$Preis+200;
    }
        else if ($extra=="Versicherung"){
        $Preis=$Preis+100;
    }
        else if ($extra=="Allinkl"){
        $Preis=$Preis+750;
    }
        else if ($extra=="4Sterne upgrade"){
        $Preis=$Preis+1000;
    }

        else {  
            echo "Error Code 3000"; }
                            }//end foreach extras
    ?>
    <br />
    <?php
        echo "Ihr gew&auml;hlter Flughafen ist: ".$_POST['Flughafen'];  
    ?>
    <br />
    <?php
        $check1=$_POST['Reiseart'];
        $check2=$_POST['Flughafen'];
        if ($check1=='pauschal'){
        $Preis=$Preis+525; }
        else if ($check1=='stadt'){
        $Preis=$Preis+400;}
        else if ($check1=='wanderung'){
        $Preis=$Preis+150;}
        else {
        $Preis=$Preis+300;}

        if ($check2=='Frankfurt'){
        $Preis=$Preis+100; }
        else if ($check2=='Bonn'){
        $Preis=$Preis+50;}
        else {
        $Preis=$Preis;}
        echo "Der Preis betr&auml;gt : $Preis";
    ?>
    <?php 
        } else {            //Ende if isset start of else Html part
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
        <table cellpadding="0" border="0">
            <tr>
                <td> <h1>Adresse </h1> </td>
            </tr>
            <tr>
                <td>Anrede:</td>
                <td> <select style="margin-left:20px" name="Anrede" size="1" >
                    <option value="Frau">Frau</option>
                    <option value="Herr">Herr</option>
                     </select>
                </td>
            </tr>
            <tr>
                <td>Titel:</td>
                <td> <select style="margin-left:20px" name="Titel" size="1" >
                    <option></option>
                    <option>Dr.</option>
                    <option>Prof.</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>Vorname:</td>
                <td> 
                <input type="text" style="background-color:#EFFBF5; margin-left:20px;" name="Vorname" /> 
                </td>
            </tr>
            <tr>
                <td>Nachname:</td>
                <td> 
                <input type="text" style="background-color:#EFFBF5; margin-left:20px;" name="Nachname" />
                </td>
            </tr>
            <tr>
                <td>Strasse:</td>
                <td> 
                <input type="text" style="background-color:#EFFBF5; margin-left:20px;" name="Strasse" />
                </td>
            </tr>
            <tr>
                <td>PLZ:</td>
                <td> 
                <input type="text" style="background-color:#EFFBF5; margin-left:20px;" name="PLZ"  />
                </td>
            </tr>
            <tr>
                <td>Ort:</td>
                <td> 
                <input type="text" style="background-color:#EFFBF5; margin-left:20px;" name="Ort"  />
                </td>
            </tr>
            <tr>
                <td>E-mail:</td>
                <td> 
                <input type="text" style="background-color:#EFFBF5; margin-left:20px;" name="E-mail" />
                </td>
            </tr>
        </table>
.
.
.
.
.
.
.
.

        <p style="align:center">
            <input type="submit" name="Buchung" value="Buchen"/> 
            <input type="reset" name="Abbrechen" value="Abbrechen"/>
        </p>
    </form>
    <?php } ?>
</div>

我刚刚发布了整个PHP代码和重要的表单部分。

对于您的许多名称属性和POST数组,这里有一个字母大小写问题。

例如:name="vorname"$_POST['Vorname']以及大写字母"V"。

这些都是区分大小写的,你也需要为其他人做同样的事情。

正如我在评论中所说,A != a

仅供参考:!=翻译为"不平等"。


错误报告添加到文件顶部,这将有助于查找错误。

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code

旁注:错误报告只能在临时阶段进行,而不能在生产阶段进行。