Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

why a parse error on this if/else?

Posted on 2007-11-17
4
Medium Priority
?
218 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 1000 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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 count occurrences of each item in an array.
Suggested Courses

824 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