I have two tables on a forum that I am referencing via a SELECT query. One table is the phpBB_users table, which holds the basic data for a member while the second table, phpbb_profile_fields_data, holds details such as address, email, phone, etc. Both tables use user_id as the key. My form selects the $smode parameter, which lists the various column headings to search for and the $parameter variable, which enters the actual data to search for. The results are displayed in an HTML table.
Here's my code:
$conn = new mysqli('localhost',$user,$pass,$database);
$sql = "SELECT * FROM phpbb_users
INNER JOIN phpbb_profile_fields_data ON phpbb_users.user_id = phpbb_profile_fields_data.user_id
WHERE $smode = $parameter
ORDER BY username";
$result = $conn->query($sql);
If I select group_id (which is in the phpbb_users table) as my $smode variable and enter a given group number as the $parameter variable, I get a nice listing of the members within that group. If I change the $smode variable to pf_user_lastname (which is in the phpbb_profile_fields_data table) and enter a common last name I don't get any results. The same holds true if I use username as the $smode variable (which is in the phpbb_users table). I get no results. The group_id column is an integer while the other two are alphanumeric variables but when I change the $smode to pf_mh_year, which is a 4 digit integer in the phpbb_profile_fields_data table, I still don't get any results. I get no error messages in the error_log because $result->num_rows is zero - except for the first case where the listing displays.