php - 关闭 php 标签时出错

标签 php html

<分区>

https://bpaste.net/show/557a8418f211

该链接包含我遇到的错误。似乎我在某处缺少一个右括号,我无法弄清楚。当我将右括号添加到主 if 语句时,它在结束 PHP 标记中给我一个错误。当我删除它时,我在该行收到错误消息。

[root@li71-58 html]# php testmail.php

PHP Warning: Zend OPcache huge_code_pages: madvise(HUGEPAGE) failed: Invalid argument (22) in Unknown on line 0 PHP Parse error: syntax error, unexpected end of file in /var/www/html/testmail.php on line 70 [root@li71-58 html]#

最佳答案

在else之后你已经留下了一个大括号,现在使用这段代码

<?php
            // define variables and set to empty values
            $lnameErr = $emailErr = $fnameErr =  "";
            $fname = $emailaddr = $lname = $phone  = "";

            if ($_SERVER["REQUEST_METHOD"] == "POST") {
                    if (empty($_POST["fname"])) {
                            $fnameErr = "First name is required";
                    }
                    else {
                            $fname = test_input($_POST["fname"]);
        // check if name only contains letters and whitespace for first name
                            if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
                                    $nameErr = "Only letters and white space allowed";
                            }
                    }

                    if (empty($_POST["lname"])) {
                            $lnameErr = "Last name is required";
                    }
                    else {
                            $lname = test_input($_POST["lname"]);
        // check if name only contains letters and whitespace for last name
                            if (!preg_match("/^[a-zA-Z ]*$/",$lname)) {
                                    $lnameErr = "Only letters and white space allowed";
                            }
                    }


                    if (empty($_POST["email"])) {
                            $emailErr = "Email is required";
                    }
                    else {
                            $email = test_input($_POST["email"]);
        // check if e-mail address is well-formed
                            if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                                    $emailErr = "Invalid email format";
                            }
                    }

            }

        // Passes input to email

            else {
                    (isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['email'])
                    && isset($_POST['phone']) && isset($_POST['county']) && isset($_POST['floor'])
                    && isset($_POST['descr'])); {

                    $data = $_POST['firstname'] . ' ' . $_POST['lastname'] . "\n" .
                    $_POST['email'] . "\n" . $_POST['phone'] . "\n" .
                    $_POST['county'] . "\n" . $_POST['floor'] . "\n" . $_POST['descr'] . "\n";


                    mail('craftsllc1@gmail.com', 'Estimation Inquery', $data);
            }
            }



            function test_input($data) {
                    $data = trim($data);
                    $data = stripslashes($data);
                    $data = htmlspecialchars($data);
                    return $data;
            }

            echo "Thank you for your inquery! <br/> An estimator will be with right with you";

    ?>

这是你错过花括号的地方

// Passes input to email

            else {
                    (isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['email'])
                    && isset($_POST['phone']) && isset($_POST['county']) && isset($_POST['floor'])
                    && isset($_POST['descr'])); {

                    $data = $_POST['firstname'] . ' ' . $_POST['lastname'] . "\n" .
                    $_POST['email'] . "\n" . $_POST['phone'] . "\n" .
                    $_POST['county'] . "\n" . $_POST['floor'] . "\n" . $_POST['descr'] . "\n";


                    mail('craftsllc1@gmail.com', 'Estimation Inquery', $data);
            }
            } // this is brace you missed

关于php - 关闭 php 标签时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44842193/

相关文章:

php - 为什么 PHP 中的反序列化总是返回 false?

PHP 函数和 SQL 访问分层

html - "horizontal" headless 表的语义结构应该是什么?

javascript - .val().trigger ('change' ) 实际上在做什么?

regex - 如何使用 HTML5 验证日期模式

php - paypal 不发送实时 ipn 详细信息

php - 运行 Composer Laravel 8 时出现 Symfony 进程错误

php - 从 xml 响应中提取 url 并重定向

html - 我的 <div> 与我的下拉选项卡重叠

javascript - 如何在 HTML 中的每个项目之间延迟打印列表