PHP 最后一行语法错误?

发布于 2024-12-26 10:02:20 字数 839 浏览 0 评论 0 原文

<?php
if (!isset($_POST['ign'], $_POST['email'])) {
    if($_POST['ign'] && $_POST['email']){
    echo "Please fill out all of the fields!";
        die;
}

if (empty($_POST['ign']) || empty($_POST['email'])) { 
    echo ("Please enter all of the values!"); 
    die;
}

if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
    $email = $_POST['email'];
    echo ("Thanks, " . htmlentities($_POST['ign']) . ", you will recieve an email when the site is complete!");

}

else {
    echo "Your email was invalid!";
    die;
}
?>

我在最后一行遇到语法错误,其中 ?>;是..

另外,只是一个随机的旁注,任何人都可以教我如何将其插入到我的代码中吗?

$valid = (bool)preg_match('/^[a-zA-Z0-9]{1,30}$/', $_POST['username']);

它只是

if ($valid == TRUE) {
////////
}

或者声明该变量已经在运行它?

<?php
if (!isset($_POST['ign'], $_POST['email'])) {
    if($_POST['ign'] && $_POST['email']){
    echo "Please fill out all of the fields!";
        die;
}

if (empty($_POST['ign']) || empty($_POST['email'])) { 
    echo ("Please enter all of the values!"); 
    die;
}

if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
    $email = $_POST['email'];
    echo ("Thanks, " . htmlentities($_POST['ign']) . ", you will recieve an email when the site is complete!");

}

else {
    echo "Your email was invalid!";
    die;
}
?>

I'm getting a syntax error on the last line where ?> is..

Also, just a random side note, can anyone teach me how to insert this into my code?

$valid = (bool)preg_match('/^[a-zA-Z0-9]{1,30}$/', $_POST['username']);

is it just

if ($valid == TRUE) {
////////
}

or is declaring that variable already running it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

骷髅 2025-01-02 10:02:20

第一个 if 块中缺少结束大括号 }

You have a missing ending brace } in the first if block.

小忆控 2025-01-02 10:02:20

如果不遵循脚本的逻辑,您将有五个左大括号 { 和四个右大括号 }

Without following the logic of your script, you have five open braces { and four closed braces }

萌梦深 2025-01-02 10:02:20

您在 if (!isset($_POST['ign'], $_POST['email'])) 行周围打开两个作用域(使用 {),因此您需要在需要的地方关闭悬空的那个。

You open two scopes (with {) around the if (!isset($_POST['ign'], $_POST['email'])) line, so you need to close the dangling one where you need to.

北方。的韩爷 2025-01-02 10:02:20

您可以从上一个问题 验证电子邮件错误 中获取代码,并添加测试用户名的长度并检查用户名是字母数字,如下所示:

<?php
if (isset($_POST['ign'], $_POST['email'])) {//do the fields exist
    if($_POST['ign'] && $_POST['email']){ //do the fields contain data
        if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {//is the email address of valid form
            if(ctype_alnum($ign) && ($ign.length > 0) && ($ign.length <= 30)){//is ign alphanumeric and between 1 and 30 characters long
                echo ("Thanks, " . htmlentities($_POST['ign']) . ", you will recieve an email when the site is complete!");
            }
            else{
                echo ("Please enter a valid user name!");
            }
        }
        else{
            echo ("Please enter a valid email!");
        }
    }
    else {
        echo ("Please enter all of the values!");
    }
}
else {
    echo ("Error in form data!");
}
?>

注意:如果我假设 $_POST['ign'] 是您在该行中要说的内容(bool)preg_match('/^[a-zA-Z0-9]{1,30}$/', $_POST['username']) ,错误...发布更多详细信息关于你需要什么,我会更新我的答案。

You can take the code from your last question, Validate Email Error , and add a test for length of username and check username is alphanumeric like this:

<?php
if (isset($_POST['ign'], $_POST['email'])) {//do the fields exist
    if($_POST['ign'] && $_POST['email']){ //do the fields contain data
        if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {//is the email address of valid form
            if(ctype_alnum($ign) && ($ign.length > 0) && ($ign.length <= 30)){//is ign alphanumeric and between 1 and 30 characters long
                echo ("Thanks, " . htmlentities($_POST['ign']) . ", you will recieve an email when the site is complete!");
            }
            else{
                echo ("Please enter a valid user name!");
            }
        }
        else{
            echo ("Please enter a valid email!");
        }
    }
    else {
        echo ("Please enter all of the values!");
    }
}
else {
    echo ("Error in form data!");
}
?>

Note: If my assumption that $_POST['ign'] is what you meant to say to in the line (bool)preg_match('/^[a-zA-Z0-9]{1,30}$/', $_POST['username']) ,is wrong ... post more details on what you need and I'll update my answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文