解析错误:语法错误,意外'{',期待'('在C:\ xampp \ htdocs \ vft_forum \ admin \ admin_forum \ poster.php第189行

时间:2017-01-02 12:09:25

标签: javascript php html

我在文件上添加一些行后尝试打开文件时遇到了这个错误。这是我的代码

if($topic=="WINDOWS"){?>

    <script>
        window.location = 'home.php';
    </script>   
<?php }elseif($topic=="MAC"){?>

    <script>
        window.location = 'mac.php';
    </script>   
<?php }elseif($topic=="LINUX"){?>

    <script>
        window.location = 'linux.php';
    </script>   
<?php }elseif($topic=="ANDROID"){?>

    <script>
        window.location = 'android.php';
    </script>   
<?php  }elseif($topic=="PROGRAMMING"){?>

    <script>
        window.location = 'program.php';
    </script>   
<?php }elseif($topic=="HARDWARE"){?>

    <script>
        window.location = 'hardware.php';
    </script>   
<?php }elseif($topic=="IOS"){?>

    <script>
        window.location = 'ios.php';
    </script>   
<?php }else {?>

    <script>
        window.location = 'msoffice.php';
    </script>   
<?php  } 
}?>

错误发生在以HARDWARE开头的行上。我试过检查,但我发现错误。有人可以帮我这个吗?提前谢谢

3 个答案:

答案 0 :(得分:2)

最后有一个'}'。删除它。

答案 1 :(得分:2)

Suggestion:- use switch() cases instead of this much lines of code.

BTW properly formated code is:-

if($topic=="WINDOWS"){?>

    <script>
        window.location = 'home.php';
    </script>   
<?php }elseif($topic=="MAC"){?>

    <script>
        window.location = 'mac.php';
    </script>   
<?php }elseif($topic=="LINUX"){?>

    <script>
        window.location = 'linux.php';
    </script>   
<?php }elseif($topic=="ANDROID"){?>

    <script>
        window.location = 'android.php';
    </script>   
<?php  }elseif($topic=="PROGRAMMING"){?>

    <script>
        window.location = 'program.php';
    </script>   
<?php }elseif($topic=="HARDWARE"){?>

    <script>
        window.location = 'hardware.php';
    </script>   
<?php }elseif($topic=="IOS"){?>

    <script>
        window.location = 'ios.php';
    </script>   
<?php }else {?>

    <script>
        window.location = 'msoffice.php';
    </script>   
<?php  } ?>

Note:-

1.remove the very last }.

2.Try to do proper Indenting of code.

3.Try to use some code-editor which will let you know automatically about these type of errors while coding itself.

答案 2 :(得分:1)

<?php
switch ($topic) {
    case "WINDOWS":
        $url = 'home.php';
        break;
    case "MAC":
        $url = 'mac.php';
        break;
    //more cases ......
    default:
        $url = 'msoffice.php';
        break;
}
?>
 <script>
   window.location = '<?php print $url; ?>';
 </script>