Solved

why a parse error on this if/else?

Posted on 2007-11-17
4
207 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
Comment Utility
You are missing a } on the else

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

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
Comment Utility
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
Comment Utility
correction

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

Author Comment

by:St_Aug_Beach_Bum
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
XSS cleaning when using ajax & json encode 5 38
Php Array Diff 3 26
mysql Encryption with PHP 8 45
PHP loop not working 4 29
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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 look for a specific file type in a local or remote server directory using PHP.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now