Solved

Can't find what is wrong with my syntax using an if statement in a query

Posted on 2013-01-13
2
291 Views
Last Modified: 2013-01-13
Can someone see what is wrong with my syntax (it may be completely obvious or for some reason impossible to do. I'm not particularly good at this)

I'm trying to say more or less:
if the Session variable: switch_user_id has a value, use it, otherwise use the session variable user_id value instead. Below is part of a constructed query using datatables.net.

$sWhere .= " AND subscribers.account_id=".
if (isset($_SESSION['switch_user_id']))
{ 
$_SESSION['switch_user_id'];
} else { 
$_SESSION['user_id'];
};

Open in new window


I am using session_start(); at the top of my page.
Get this error in my logs:
PHP Parse error: syntax error, unexpected T_IF
0
Comment
Question by:tjyoung
2 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
ID: 38772838
$id=(isset($_SESSION['switch_user_id'])) ? $_SESSION['switch_user_id'] : $_SESSION['user_id'];
$sWhere .= " AND subscribers.account_id=".$id;


Cd&
0
 
LVL 1

Author Closing Comment

by:tjyoung
ID: 38772854
much nicer. Thanks!
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

830 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