-5

i have got that error when trying to open my files after adding some line on on the file. here are my codes

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  } 
}?>

the error occurred on line that started with HARDWARE. I have tried to check but i couldint find that error. could some one help me with this? thanks in advance

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
oedward38
  • 3
  • 1
  • 7

3 Answers3

2

Have an '}' in the very end. Remove that.

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Michael
  • 405
  • 4
  • 10
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.

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
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>
Eugen
  • 1,356
  • 12
  • 15