2013-04-10 128 views
0

我是PHP新手,我面临语法错误。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"]); 
    } 

?> 

错误:

Parse error: syntax error, unexpected '||' (T_BOOLEAN_OR), expecting ')' in /home/jharvard/vhosts/localhost/html/register.php on line 9

我很新的PHP,这是可能的这段代码有多个错误。 作为参考,道歉只是简单地渲染一个抱歉的消息以及额外的输入,渲染只是一个简化渲染过程的模板。

+2

'如果(空($ _ POST [ '名']))'你有一个额外的括号封闭的if语句 – Pankrates 2013-04-10 14:47:53

+0

感谢,定了! – 2013-04-10 14:49:45

+0

PHP错误几乎总会给你足够的信息来发现问题。如果你学会阅读错误,你永远不会有语法问题。 – Narek 2013-04-10 14:50:01

回答

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']) { 
+0

你缺少一个括号 – scones 2013-04-10 14:49:18

+0

谢谢,你和恶作剧指出了这两个错误:D – 2013-04-10 14:50:19

5

变化:

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

到:

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

不只是发布两个不同的单行字代码。使用第二行加上'^^^'来表示你在哪里做了改变。 – 2013-04-10 14:49:36

0

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

if(empty($_POST['username']) || empty($_POST['password']) || ($_POST['password'] != $_POST['confirmation'])){ 
     apologize('You did something wrong!'); 
    }