Solved

why a parse error on this if/else?

Posted on 2007-11-17
4
208 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 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access Object's Property 9 22
get domain with php 7 20
Website Interactive tool that will do calculations 3 31
php construct 5 13
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

867 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

20 Experts available now in Live!

Get 1:1 Help Now