tags:

views:

27

answers:

2

Hello,

I am trying to use the code below to do the following;

  1. In a MySQL table called submission, check to see if subcheck = 1 for the row where submissionid = $submissionid.

  2. If the answer to #1 above is yes, then take the email field from a MySQL table called "login" from the row where username = $submittor', and then email $comment to that address.

It's not working. Any ideas why not?

Thanks in advance,

John

$querye = mysql_query("SELECT subcheck FROM submission WHERE subcheck = '1' AND WHERE submissionid = '$submissionid' ");

if (mysql_num_rows($querye) == 1)
{

$mailaddress = "SELECT email FROM login WHERE username = '$submittor'";

$queryem = mail($mailaddress, "Someone has commented on your submission $submission.", $comment, "[email protected]");

mysql_query($queryem) or die(mysql_error());

}
else
{
//your subcheck is not 1 / nothing was found
}
+1  A: 

You are using $mailaddres before fetching it from DB.

You should do something like:

$email_query = "SELECT email FROM login WHERE username = '$submittor'";
$result = mysql_query($email_query);
if (!$result) {
        trigger_error('Invalid query: ' . mysql_error()." in ".$email_query);
}

if($row = mysql_fetch_assoc($result)) {
        $mailaddress = $row['email'];
        $queryem = mail($mailaddress, "Someone has commented on your submission 
                        $submission.", $comment, "[email protected]");
}else{
        // no rows found.
}
codaddict
Okay, thanks. How could I fetch it from the database?
John
+2  A: 

your query is bad, you got an extra "WHERE" in

q: SELECT subcheck FROM submission WHERE subcheck = '1' AND WHERE submissionid = '$submissionid'

it should be something like

q: SELECT subcheck FROM submission WHERE subcheck = '1' AND submissionid = '$submissionid';

try it, hope this helps.

alien052002
+1: Good catch.
codaddict
:) thx much, but not nearly as complete as your response. wanted to vote up earlier, but couldn't. too new. now i can :)
alien052002