whats wrong with this query

I have this query and I want to look at the Name field and get only the result where name field matches the name in the session
the session is $_Session['userb'] and gives me names like John Devon etc

the problem is that even though I have John Devon in my database in the Name field, it doesn't show me any records and it says 0 records.
I think I am doing something wrong in this query and may be it is not taking the name string correctly
Anyhelp will be appreciated.
  $users = $_SESSION['userb'];
 $nuser = "Name= ".$users;
 $sql = "SELECT ID, `Name`, `Phone`, `Email`, `ipaddress`, `completed`, `City`, `Training`, `Date`,  FROM `Table1` where '".$nuser."' ";
  if (isset($order) && $order!='') $sql .= " order by `" .sqlstr($order) ."`";
    if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype);
  $res = mysql_query($sql, $conn) or die("error users " .mysql_error());
  return $res;  

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you need to change this:

 $sql = "SELECT ID, `Name`, `Phone`, `Email`, `ipaddress`, `completed`, `City`, `Training`, `Date`,  FROM `Table1` where '".$nuser."' ";

to this:

 $sql = "SELECT ID, `Name`, `Phone`, `Email`, `ipaddress`, `completed`, `City`, `Training`, `Date`,  FROM `Table1` where 'Name' = '".$nuser."' ";
syedasimmeesaqAuthor Commented:
That still does the same thing.. no records.
sorry my fault I did not see you were setting the variable to include the field name.

try this:

$sql = "SELECT ID, `Name`, `Phone`, `Email`, `ipaddress`, `completed`, `City`, `Training`, `Date`,  FROM `Table1` where `Name` = '". $users . "' ";;
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  $nuser = "Name= '$users' " ; //to quote the name.
syedasimmeesaqAuthor Commented:
oh sorry guys the problem was in other query. which was

$sql = "SELECT COUNT(*) FROM `tatracking_survey`  Name = '".$users."' ";
and I was missing where
$sql = "SELECT COUNT(*) FROM `tatracking_survey` where Name = '".$users."' ";

however now I am getting the records but I am also getting the rows where Phone field is empty. How can I rewrite the above query so it doesn't show any records where Phone field is null. I tried
$sql = "SELECT ID, `Name`, `Phone`, `Email`, `ipaddress`, `completed`, `City`, `Training`, `Date`,  FROM `Table1` where `Phone` is not null AND `Name` = '". $users . "' ";
but that didn't work.
maybe it is NOT NULL but blank, you can try this:

"SELECT ID, `Name`, `Phone`, `Email`, `ipaddress`, `completed`, `City`, `Training`, `Date`,  FROM `Table1` where `Phone` is not null AND LTRIM(`Phone`) <> '' AND `Name` = '". $users . "' ";

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
syedasimmeesaqAuthor Commented:
thanks. In addition to that I also had to but that in here too
$sql = "SELECT ID, `Name`, `Phone`, `Email`, `ipaddress`, `completed`, `City`, `Training`, `Date`,  FROM `Table1` where `phone` <> '' AND `Name` = '". $users . "' ";;
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.