Richard M
Richard M

Reputation: 1465

Weird if elseif logic in PHP

I have a page that displays certain HTML based on the query string that is loaded in the URL.

Here is a sample of my code.

<?php 
    // grab querystring section
    $w = getQuerys('section');

    if ($w == "main") {?>

DISPLAY HTML VERSION ONE

<? } else if ($w == 'types')  {?>

DISPLAY HTML VERSION TWO

<?php }  ?>

For some reason, this logic works fine on my Web hosting site, but not on my workstation using XAMPP. When I run this on my workstation, both HTML VERSION ONE AND TOW are displayed at the same time on the page.

I'm afraid I'm at a bit of a loss for this. I've confirmed that the getQuerys function works fine by echoing out the $w variable.

Thanks in advance for any help that you can provide.

Upvotes: 0

Views: 74

Answers (1)

KGolding
KGolding

Reputation: 380

You are mixing php shorts tags with long tags. I expect XAMPP doesn't have short tags enabled, so change the following line:

<?php } else if ($w == 'types')  {?>

Upvotes: 4

Related Questions