0

我是 PHP 新手,遇到语法错误。

代码:

<?php

    // configuration
    require("../includes/config.php");

    // if form was submitted
    if ($_SERVER["REQUEST_METHOD"] == "POST")
    {
        if(empty($_POST['username'])) || empty($_POST['password'] || $_POST['password'] != $_POST['confirmation']){
            apologize('You did something wrong!');
        }
    }
    else
    {
        // else render form
        render("register_form.php", ["title" => "Register"]);
    }

?>

错误:

解析错误:语法错误,意外的“||” (T_BOOLEAN_OR),在第 9 行的 /home/jharvard/vhosts/localhost/html/register.php 中期待 ')'

我对 PHP 很陌生,这段代码可能有多个错误。作为参考,apouse 只是在附加输入的同时呈现一个抱歉的消息,而 render 只是一个使用模板简化呈现过程的函数。

4

3 回答 3

5

改变:

if(empty($_POST['username'])) || empty($_POST['password'] || $_POST['password'] != $_POST['confirmation']){

至:

if(empty($_POST['username']) || empty($_POST['password']) || $_POST['password'] != $_POST['confirmation']){
                           ^                            ^
于 2013-04-10T14:48:26.863 回答
3

括号太多。代替

if(empty($_POST['username'])) || empty($_POST['password'] || $_POST['password'] != $_POST['confirmation']){
                            ^                            ^
                            too much here                too less here 

你应该有

if( empty($_POST['username']) || empty($_POST['password']) || $_POST['password'] != $_POST['confirmation']) {
于 2013-04-10T14:47:50.767 回答
0

这是因为太多的paranethesis。尝试这个,

 if(empty($_POST['username']) || empty($_POST['password']) || ($_POST['password'] != $_POST['confirmation'])){
        apologize('You did something wrong!');
    }
于 2013-04-10T14:49:27.257 回答