syedasimmeesaq
asked on
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.
Thanks
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.
Thanks
if(isset($_SESSION['userb'])){
$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;
}
ASKER
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 . "' ";;
try this:
$sql = "SELECT ID, `Name`, `Phone`, `Email`, `ipaddress`, `completed`, `City`, `Training`, `Date`, FROM `Table1` where `Name` = '". $users . "' ";;
Try
$nuser = "Name= '$users' " ; //to quote the name.
$nuser = "Name= '$users' " ; //to quote the name.
ASKER
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.
Thanks
$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.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 . "' ";;
$sql = "SELECT ID, `Name`, `Phone`, `Email`, `ipaddress`, `completed`, `City`, `Training`, `Date`, FROM `Table1` where `phone` <> '' AND `Name` = '". $users . "' ";;
$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."' ";