anitag95
anitag95

Reputation: 309

Using if-statements in PHP to print HTML

I'm fairly new to PHP and I've been trying to construct some code to print basic HTML, however the code causes an error 500 whenever used. I am guessing it is a syntax error since I've tried the code in a couple of forms and nothing seems to work (including removing the database lookup and just trying to compare to set values to each other). The script needs to get a variable from the db, compare it to a set value and print the HTML if true, here is the code I am trying:

<?php
    $db = &JFactory::getDBO();
    $id = JRequest::getString('id');
    $db->setQuery('SELECT #__categories.title FROM #__content, #__categories WHERE #__content.catid = #__categories.id AND #__content.id = '.$id);
    $category = $db->loadResult(); ?>
  <?php if strcmp($category,"Blog")==0 : ?>

      <div style="display: -webkit-inline-box" class="sharelogos">
        <a href="http://www.facebook.com/sharer.php?u=<?php echo "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" target="_blank">  <img src="/images/sharing-icons/facebook.png" width="30px" alt="Facebook" /></a>
      </div>

<?php endif; ?>

Any help will be appreciated, thanks!

Upvotes: 1

Views: 245

Answers (1)

Halayem Anis
Halayem Anis

Reputation: 7785

You if is incorrect, try like this

<?php if (strcmp($category,"Blog")==0) { ?>

      <div style="display: -webkit-inline-box" class="sharelogos">
        <a href="http://www.facebook.com/sharer.php?u=<?php echo "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" target="_blank">  <img src="/images/sharing-icons/facebook.png" width="30px" alt="Facebook" /></a>
      </div>

<?php } ?>

Upvotes: 3

Related Questions