Code:
function emailcontractors($id) {
$sql="SELECT * FROM projects WHERE id = '$id'"; //Get project info
$result=mysql_query($sql) or DIE("Could not select database for emailing contractors");
$row=mysql_fetch_assoc($result); //Put project info into an array
$sql2="SELECT * FROM tc_users WHERE (user_from = '$row[state]' OR user_state2 = '$row[state]' OR user_state3 = '$row[state]') && (user_trade = '$row[trade]' OR user_trade1 = '$row[trade]' OR user_trade2 = '$row[trade]' OR user_trade3 = '$row[trade]')";
$result2=mysql_query($sql2) or DIE("Could not select database for emailing contractors part 2");
if(mysql_num_rows($result2)) {
while($row2=mysql_num_rows($result2)) {
$contemail=$row2['user_email'];
$contmsg="A new project has been submitted to Team Contractor that matches the criteria you have in your profile.\n
The details are as follows:\n
Contact Information\n";
$contmsg .= $row['contact']."\n";
$contmsg .= $row['ptype']."\n";
$contmsg .= $row['state']."\n";
$contmsg .= $row['city']."\n";
$contmsg .= $row['zip']."\n";
$subject="Team Contractor Project";
contractoremail($contemail, $contmsg, $subject);//send email to contractors
}
} else {
$ownermsg="We apologize but there are no contractors matching your area or specific criteria.<br>The staff at Team Contractor will contact you within 2 days with information on your next course of action.<br>Regards,<br>Team Contractor Staff<br><br>Ref - id{$id}";
$owneremail=$row['email'];
$subject='Team Contractor - No Contractors Available';
emailowner($owneremail, $ownermsg, $subject);
}
}
Essentially I'm trying to match up the 2 mysql fields ($row[state] and $row[trade] from sql) and compare that to 3 state fields and 4 trade fields in sql2. The initial $id in the function is output from an INSERT function with mysql_insert_id(); or last inserted id.
I ran this code and it sent about 10000 emails to me before John and Jazzee got it stopped (thanks btw).. but I'm just not seeing why it would do that. Been working on it too long I guess.
Any help greatly appreciated.