mysql - WHERE NOT IN command does not work in PHP but works in SQL -



mysql - WHERE NOT IN command does not work in PHP but works in SQL -

so i'm trying select values 1 table not exist in selection of table.

this sql command run:

select `u882219588_data`.`user`.`user_name`, `u882219588_data`.`user`.`email`, `u882219588_data`.`user`.`name`from `u882219588_data`.`user` `u882219588_data`.`user`.`user_name` not in (select `u882219588_data`.`user_groups`.`user_name` `u882219588_data`.`user_groups` `u882219588_data`.`user_groups`.`group_id` = '$group_id');

and works in phpmyadmin perfectly! when utilize in php:

//login info on top if (isset($_get['group_id'])) { $array = array(); $response = array(); $groupid = $_get['group_id']; $result = mysqli_query($con, "select `u882219588_data`.`user`.`user_name`, `u882219588_data`.`user`.`email`, `u882219588_data`.`user`.`name` `u882219588_data`.`user` `u882219588_data`.`user`.`user_name` not in (select `u882219588_data`.`user_groups`.`user_name` `u882219588_data`.`user_groups` `u882219588_data`.`user_groups`.`group_id` = '$group_id');"); while($obj = mysqli_fetch_object($result)) { $array[] = $obj; } $response["success"]=1; $response["result"]=$array; $response["group_id"] = $groupid; print(json_encode($response)); } mysqli_close($con);

it selects every row user table! don't happening here. tried alter php bit, utilize approach, same result happens.

later, found out

select `u882219588_data`.`user_groups`.`user_name` `u882219588_data`.`user_groups` `u882219588_data`.`user_groups`.`group_id` = '$group_id'

was returning empty set, have no thought why because works in phpmyadmin.

does see mistake?

typo: variable called

$groupid = $_get['group_id'];

but you're using $group_id in query.

also read @tadman's comment or you'll run security issues sql-injection.

php mysql sql

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -