Jump to content

Select from 2 tables? Help.


tebrown

Recommended Posts

Hey Guys,

 

After searching on google and other forums for solutions for this warning im still having trouble as to why it wont identify if an email already exsists in either of the 2 tables (managers, players).

 

Warning: mysql_result() expects parameter 1 to be resource, boolean given in /Users/Tim/Sites/DMS/RoutoSMS/functions.php on line 71

 


function emailExists($email) {
$query = mysql_query("SELECT `managers`.`email`, `players`.`email` FROM `managers`, `players` WHERE `email` = '$email'");
return (mysql_result($query, 0) > 0) ? true : false ;
}

 

This is the code where it identifies the function:

 


if(emailExists($email)) {
$errors[] = "Email already registered.";
}

Link to comment
https://forums.phpfreaks.com/topic/260772-select-from-2-tables-help/
Share on other sites

99% of the time that error message means your query failed. There's a problem with it and MySQL couldn't execute it.

 

The actual problem here is moot because your query needs to change. It won't do what you're trying to do. So give it another shot. Try the most obvious solution first, and once that's working you can think about whether there's a better way of doing it.

Ok i did give it another shot. Although this time, in my database i have an email in the 'managers' table, and when i try to use this function it still inserts a new email into the players table. Where it should say something like 'Email already registered' because of it already in the members table.

 


function emailExistsPlayers($email) {
$query = mysql_query("SELECT COUNT(managers.id) AS mCount, COUNT(players.id) AS pCount
          FROM managers, players
          WHERE managers.email = '$email'
          OR players.email = '$email'");
return (mysql_result($query, 0) > 0) ? true : false ;
}

what about this?

function emailExistsPlayers($email){
$query = <<<QUERY
SELECT count(emailCount) as emailTotal FROM
(
(select email as emailCount FROM managers WHERE email='$email')
UNION
(SELECT email as emailCount FROM players WHERE email='$email')
) AS emailTbl
QUERY;
$result = mysql_query($query) or die (mysql_error());
$row = mysql_fetch_assoc($result);
if ($row['emailTotal'] >= 1){
$return = true;
}
else{
$reurn = false;
}
return $return;
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.