By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,347 Members | 2,091 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,347 IT Pros & Developers. It's quick & easy.

structure a select statement with multiple where

P: 1
Hi,
I am doing a project with dreamweaver and i ran into a hitch with my select statement.
I have this

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2.     FROM client, `statement`
  3.     WHERE client.client_id = `statement`.client_id 
when i execute this it selects everybody in the database. So i want to add another WHERE statement to this query, this time one that compares the client.username with the session variable "MM_Username".
Thank you in anticipation of solving this for me!
So I am looking at something like this

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2.     FROM client, `statement`
  3.     WHERE client.client_id = `statement`.client_id  AND WHERE client.username = '$_SESSION['MM_Username']'
The session php code is as follows



Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     if (!isset($_SESSION)) {
  3.       session_start();
  4.     }
  5.     $MM_authorizedUsers = "";
  6.     $MM_donotCheckaccess = "true";
  7.  
  8.     // *** Restrict Access To Page: Grant or deny access to this page
  9.     function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  10.       // For security, start by assuming the visitor is NOT authorized. 
  11.       $isValid = False; 
  12.  
  13.       // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  14.       // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  15.       if (!empty($UserName)) { 
  16.         // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
  17.         // Parse the strings into arrays. 
  18.         $arrUsers = Explode(",", $strUsers); 
  19.         $arrGroups = Explode(",", $strGroups); 
  20.         if (in_array($UserName, $arrUsers)) { 
  21.           $isValid = true; 
  22.         } 
  23.         // Or, you may restrict access to only certain users based on their username. 
  24.         if (in_array($UserGroup, $arrGroups)) { 
  25.           $isValid = true; 
  26.         } 
  27.         if (($strUsers == "") && true) { 
  28.           $isValid = true; 
  29.         } 
  30.       } 
  31.       return $isValid; 
  32.     }
  33.  
  34.     $MM_restrictGoTo = "myflog.php";
  35.     if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  36.       $MM_qsChar = "?";
  37.       $MM_referrer = $_SERVER['PHP_SELF'];
  38.       if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  39.       if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  40.       $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  41.       $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  42.       header("Location: ". $MM_restrictGoTo); 
  43.       exit;
  44.     }
  45.     ?>
  46.  
Jan 17 '13 #1
Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,366
I don't see your query anywhere in your PHP code.

As far as your query goes, the syntax is wrong, you only need to use the WHERE clause once. And the SQL engine won't have access to your PHP variables so you will have to append the value to the SQL string in your code.
Jan 17 '13 #2

100+
P: 185
That reminds me of one mysteries select statement. It's the only case I could see where twice in a select statement:
Expand|Select|Wrap|Line Numbers
  1. SELECT SELECT FROM WHERE WHERE
It's explained very well by Serge here https://www.ibm.com/developerworks/m...here49?lang=en
Jan 25 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.