Php 未定义变量

Php 未定义变量,php,Php,我一直在第52、53、54、55行得到未定义的变量,不知道如何修复它。任何帮助都将不胜感激 <table> <form name="emailMe" id="emailMe" action="contactMe.php" method="post"> <tr><th><p>First Name </p></th> <td><p>&l

我一直在第52、53、54、55行得到未定义的变量,不知道如何修复它。任何帮助都将不胜感激

<table>
            <form name="emailMe" id="emailMe" action="contactMe.php" method="post">

                <tr><th><p>First Name </p></th> <td><p><input type="text" name="firstName" maxlength="10"value="<?php print($fName); ?>" /></p></td></tr>
                <tr><th><p>Last Name </p></th> <td><p><input type="text" name="lastName" maxlength="25"value="<?php print($lName); ?>" /></p></td></tr>
                <tr><th><p>Email </p></th> <td><p><input type="text" name="email" maxlength="50"value="<?php print($email); ?>" /></p></td></tr>
                <tr><th><p>Message </p></th> <td><p><input type="text" name="message" maxlength="250"value="<?php print($message); ?>" /></p></td></tr>
        </table>

                <p><input type="submit" name="submit" value="Submit" />
                <input type="reset" value="Clear Form" /></p>
            </form>

        <?php 

            if(isset($_POST["submit"])){

            $errorCount = 0;
            $fName      = $_POST['firstName'];
            $lName      = $_POST['lastName'];
            $email      = $_POST['email'];
            $message    = $_POST['message'];

名字

编辑:

像这样

<?php 

        if(isset($_POST["submit"])){
        $errorCount = 0;
        $fName      = $_POST['firstName'];
        $lName      = $_POST['lastName'];
        $email      = $_POST['email'];
        $message    = $_POST['message'];
        }
        else
        {
        $fName      = "";
        $lName      = "";
        $email      = "";
        $message    = "";
        }
?>

这需要超越你的HTML

编辑:

像这样

<?php 

        if(isset($_POST["submit"])){
        $errorCount = 0;
        $fName      = $_POST['firstName'];
        $lName      = $_POST['lastName'];
        $email      = $_POST['email'];
        $message    = $_POST['message'];
        }
        else
        {
        $fName      = "";
        $lName      = "";
        $email      = "";
        $message    = "";
        }
?>

这需要放在HTML的上方,在
标记中声明
像这样:

 <form name="emailMe" id="emailMe" action="contactMe.php" method="post">
<table>
                <tr><th><p>First Name </p></th> <td><p><input type="text" name="firstName" maxlength="10"value="<?php print($fName); ?>" /></p></td></tr>
                <tr><th><p>Last Name </p></th> <td><p><input type="text" name="lastName" maxlength="25"value="<?php print($lName); ?>" /></p></td></tr>
                <tr><th><p>Email </p></th> <td><p><input type="text" name="email" maxlength="50"value="<?php print($email); ?>" /></p></td></tr>
                <tr><th><p>Message </p></th> <td><p><input type="text" name="message" maxlength="250"value="<?php print($message); ?>" /></p></td></tr>
        </table>

                <p><input type="submit" name="submit" value="Submit" />
                <input type="reset" value="Clear Form" /></p>
            </form>

名字他们在
标签中声明
像这样:

 <form name="emailMe" id="emailMe" action="contactMe.php" method="post">
<table>
                <tr><th><p>First Name </p></th> <td><p><input type="text" name="firstName" maxlength="10"value="<?php print($fName); ?>" /></p></td></tr>
                <tr><th><p>Last Name </p></th> <td><p><input type="text" name="lastName" maxlength="25"value="<?php print($lName); ?>" /></p></td></tr>
                <tr><th><p>Email </p></th> <td><p><input type="text" name="email" maxlength="50"value="<?php print($email); ?>" /></p></td></tr>
                <tr><th><p>Message </p></th> <td><p><input type="text" name="message" maxlength="250"value="<?php print($message); ?>" /></p></td></tr>
        </table>

                <p><input type="submit" name="submit" value="Submit" />
                <input type="reset" value="Clear Form" /></p>
            </form>


名字

在声明变量之前,您正在使用变量。更改如下

    <?php 

                if(isset($_POST["submit"])){

                $errorCount = 0;
                $fName      = $_POST['firstName'];
                $lName      = $_POST['lastName'];
                $email      = $_POST['email'];
                $message    = $_POST['message'];

    ?>
<form name="emailMe" id="emailMe" action="contactMe.php" method="post">
    <table>
            <tr><th><p>First Name </p></th> <td><p><input type="text" name="firstName" maxlength="10"value="<?php print($fName); ?>" /></p></td></tr>
                    <tr><th><p>Last Name </p></th> <td><p><input type="text" name="lastName" maxlength="25"value="<?php print($lName); ?>" /></p></td></tr>
                    <tr><th><p>Email </p></th> <td><p><input type="text" name="email" maxlength="50"value="<?php print($email); ?>" /></p></td></tr>
                    <tr><th><p>Message </p></th> <td><p><input type="text" name="message" maxlength="250"value="<?php print($message); ?>" /></p></td></tr>
            </table>
            <p><input type="submit" name="submit" value="Submit" />
            <input type="reset" value="Clear Form" /></p>
</form>


名字

在声明变量之前,您正在使用变量。更改如下

    <?php 

                if(isset($_POST["submit"])){

                $errorCount = 0;
                $fName      = $_POST['firstName'];
                $lName      = $_POST['lastName'];
                $email      = $_POST['email'];
                $message    = $_POST['message'];

    ?>
<form name="emailMe" id="emailMe" action="contactMe.php" method="post">
    <table>
            <tr><th><p>First Name </p></th> <td><p><input type="text" name="firstName" maxlength="10"value="<?php print($fName); ?>" /></p></td></tr>
                    <tr><th><p>Last Name </p></th> <td><p><input type="text" name="lastName" maxlength="25"value="<?php print($lName); ?>" /></p></td></tr>
                    <tr><th><p>Email </p></th> <td><p><input type="text" name="email" maxlength="50"value="<?php print($email); ?>" /></p></td></tr>
                    <tr><th><p>Message </p></th> <td><p><input type="text" name="message" maxlength="250"value="<?php print($message); ?>" /></p></td></tr>
            </table>
            <p><input type="submit" name="submit" value="Submit" />
            <input type="reset" value="Clear Form" /></p>
</form>


名字

请从当前位置删除以下行,并将这些行放在表格标记之前


请从当前位置删除以下行,并将这些行放在表格标记之前


遵循以下简单步骤:

从此处更改:
名字

遵循以下简单步骤:

更改如下:
名字最好知道52-55行在代码中的位置。因为您在声明它们之前使用它们,您是否为变量设置了值,如$fName?使用
打印($\u POST)
before
if(isset($\u POST['submit'])
要知道发布了什么对不起,Alex 52-55是表单中的Tr行,最好知道52-55行在代码中的位置。因为您在声明它们之前使用它们,您是否为$fName之类的变量设置了值?使用
print\r($\u POST)
before
if(isset($\u POST['submit'])
要知道发布了什么对不起,Alex 52-55是表单中的Tr行,我尝试在表单上方声明它们,但id似乎没有解决问题。是的,因为您的代码只在设置了$\u POST时声明它们,但您的html希望在没有$\u POST的情况下始终使用它们。因此,首先你必须在html上面声明它们,其次你必须用可能为空的值初始化它们,即使未设置$\u POST。我尝试在表单上面声明它们,但id似乎没有解决问题。是的,因为你的代码只在设置$\u POST时声明它们,但你的html希望始终使用它们,即使没有设置$\u POST。因此,首先必须在html上面声明它们,其次,即使未设置$\u POST,也必须使用空值初始化它们