Solved

why a parse error on this if/else?

Posted on 2007-11-17
4
211 Views
Last Modified: 2010-08-05
Why am I getting a parse error on this?

<? if ($_SESSION['g_id']) { ?>
      this        <?} ?>
<? else { ?>      
      that  <? } ?>

I'm trying to adapt someone else's script and I don't usually write things like this.  The if statement alone works (that was the original script), but when I add the else portion (what I am trying to do) I get a parse error on that line.  Can you tell me where I am going wrong with this?    

Thanks,  Chris
0
Comment
Question by:St_Aug_Beach_Bum
  • 2
4 Comments
 
LVL 20

Expert Comment

by:steelseth12
ID: 20305331
You are missing a } on the else

<? if ($_SESSION['g_id']) { ?>
     
      this        
     
      <? } ?>
<? } else { ?>      
      that  <? } ?>
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 20305334
the code looks correct... I suggest though removing unnecessary tags...

<?php
  if ($_SESSION['g_id'])
{ ?>this<?php
}
else
 { ?>that  <?php
 }
 ?>
0
 
LVL 20

Assisted Solution

by:steelseth12
steelseth12 earned 250 total points
ID: 20305338
correction

<? if ($_SESSION['g_id']) { ?>
     
      this        
     
     
<? } else { ?>      
      that  <? } ?>
0
 

Author Comment

by:St_Aug_Beach_Bum
ID: 20305356
I don't know why moving that bracket from the php tag it was in to the other makes a difference, but like I said, I don't usually write (what little code I know how to write) like that, will have to learn more on this subject :)

Thank you both,   Chris
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question