PHP Parse error: syntax error, unexpected T

I looked at many other questions, but I can't find my own answer in it. here is my syntax error (unexpeted T_IF):

while(($rij1 = mysql_fetch_object($result1))
and( if ($voornaam=NULL) {
            $rij2 = ' ';}
elseif($voornaam!=NULL){
            $rij2 = mysql_fetch_object($result2);})

I looked at the line before the syntax, but I couldn't find what is wrong... Does someone know it?


Try rewriting your code as:

while ($rij1 = mysql_fetch_object($result1))
{
    if ($voornaam === NULL) 
    {
        $rij2 = ' ';
    } 
    else
    {
        $rij2 = mysql_fetch_object($result2);
    }
}

Edit: Corrected your condition in the first if , as @andrewsi spotted - = is an assignment operator, so previously your code was changing $voornaam to NULL , then checking if the result evaluated to true (which, of course, it never would - so the second block would always execute)

In your original code, you're using the and operator - presumably having seen it used in some well meaning but poorly coded examples like mysql_connect(...) or die('an error occurred'); .

What's happening in that example is that the result of the first statement - mysql_connect() - is checked. If it evaluates to true, the second statement never executes, but if it evaluates to false then the second statement - die('an error occurred'); - is executed. As you've just discovered, this pattern is confusing and best avoided.

链接地址: http://www.djcxy.com/p/12016.html

上一篇: 语法错误,意外的T

下一篇: PHP解析错误:语法错误,意外的T