I am having trouble retrieving records from a table in a chemical structures database I am creating with php. Whenever I use either mysql_query() or mysqli_query() the result always equals false because of the error (Table 'Crystal_Structs.BinaryCompoundList' doesn't exist) which I was told by mysqli_error().
I know the table exists and is working when I use SHOW TABLES and the CHECK TABLE queries as the table is displayed and its status is seen as okay. I am able to run Select, Insert, etc queries in both my Netbeans IDE database service area and the command line. I'm not sure what's going on but any help is greatly appreciated. Thank you.
Code Snippet:
/* Connect to local MySQL server */
$localdb = mysqli_connect("server", "user", "pass")
or die("Unable to connect to Database Server");
/*Connect to Crystal Structures db*/
mysqli_select_db($localdb, "Crystal_Structs")
or die(mysqli_error($localdb));
session_start();
$Ab=$_POST['compound'];
$spce_grp=$_POST['space_group'];
$query = 'SELECT * FROM BinaryCompoundList '
. 'WHERE compound="$_SESSION[Ab]" '
. 'AND space_group="$_SESSION[spce_grp]"';
$result = mysqli_query($localdb, $query);
if($result == false){
echo 'not a proper query:';
echo $query;
die(mysqli_error($localdb)); /*debug*/
}
$check = mysqli_num_rows($result);
if($check != 1){
die("Multiple Records");
}
SHOW TABLES query:
+---------------------------+
| Tables_in_Crystal_Structs |
+---------------------------+
| BinaryCompoundList |
| BinaryCompoundSites |
+---------------------------+
2 rows in set (0.00 sec)
CHECK TABLE BinaryCompoundList query:
+------------------------------------+-------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+------------------------------------+-------+----------+----------+
| Crystal_Structs.BinaryCompoundList | check | status | OK |
+------------------------------------+-------+----------+----------+
1 row in set (0.00 sec)
I noticed you are calling your db by two names: Crystal_Structs in the code and Crystal_Structures in your error message. Any chance you have created multiple db's along the dev path?
Other than that, must be a typo, can you show the output for SHOW TABLES?