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
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.

Link to comment
Share on other sites

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 ;
}

Link to comment
Share on other sites

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;
}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.