First, way way earlier on the page I queried database A because I was easily displaying info from that table. That query looks like this:
<?php
$server = "localhost";
$username = "YYYYYY";
$password = "YYYYYY";
$database = "YYYYYY";
$con = mysql_connect($server, $username, $password);
mysql_select_db($database, $con); // Don't actually need to make this a variable.
$id=$_GET['id'];
// query the mainDB
$sql = "SELECT * FROM brotherhood WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
echo "This person's last name is: ".$myrow["lastname"];
?>
Then later on is where I'm trying to get that one email address from database B. Here's the code I tried (including the mysql_error() ):
<?php
// query the WordPressDB
$wp_server = "localhost";
$wp_username = "XXXXXX";
$wp_password = "XXXXXX";
$wp_database = "XXXXXX";
$wp_con = mysql_connect($wp_server, $wp_username, $wp_password);
mysql_select_db($wp_database, $wp_con); // Don't actually need to make this a variable.
$id=$_GET['id'];
$wp_sql = "SELECT prefix_wordpressDB.wp_users.user_email FROM prefix_wordpressDB.wp_users
JOIN mainDB.brotherhood ON prefix_wordpressDB.wp_users.wp_login = mainDB.brotherhood.wp_user
WHERE mainDB.brotherhood.id = $id";
$wp_result = mysql_query($wp_sql);
$wp_row = mysql_fetch_array($wp_result);
if (!$wp_result) {
die('Invalid query: ' . mysql_error());
}
echo "this user\'s email address is ".$wp_row["user_email"];
?>
And the result is that most of the page displays fine, but at the bottom where I'm trying to display this person's email address I get this (and surprisingly it doesn't display tht final row of text "this user's email address is":
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/XXXXXX/public_html/domain.net/info.php on line 255
Invalid query: SELECT command denied to user 'WP_username'@'localhost' for table 'brotherhood'
I thank you for your help. I'm just having trouble figuring out how to use two tables (and two databases) for the first time.
P.S. Just to point out two similarly named entities... there is a FIELD in database A called "wp_user" and there is a TABLE in database B called "wp_users" (with an 's'). I don't think I've mixed those names up anywhere but I just wanted to point out those similar names.