PHP Code:
while ($row = mysql_fetch_array($result)) {
$emailaddress=$row['EmailAddress'];
$leadid=$row['LeadID'];
$bIsEmailValid = jValidateEmailUsingSMTP("$emailaddress", "REMOVED.com", "fraudcheck@REMOVED.com");
$emailchecker = $bIsEmailValid ? "Valid" : "Invalid";
if ($emailchecker=="Valid") {
$query3 = "UPDATE leads SET EmailCheck='PASS' WHERE LeadID='$leadid'";
} else {
$query3 = "UPDATE leads SET EmailCheck='FAIL' WHERE LeadID='$leadid'";
}
mysql_query($query3) or die(mysql_error() . ' in query ' . $query);
}
This is just a personal preference, but Instead of all that just have something like:
PHP Code:
foreach (mysql_fetch_array($result) as $row) {
$flag = (jValidateEmailUsingSMTP($row['EmailAddress'], "REMOVED.com", "fraudcheck@REMOVED.com")) : "PASS" : "FAIL";
$update_flag = "UPDATE leads
SET EmailCheck='$flag'
WHERE LeadID=' . $row['EmailAddress'] . '";
mysql_query($update_flag) or die(mysql_error() . ' in query ' . $query);
}
Here are some of the reasons I say that:
You are only using these vars once, what is the point of re-assigning them to another var?
PHP Code:
$emailaddress=$row['EmailAddress'];
$leadid=$row['LeadID'];
jValidateEmailUsingSMTP() seemingly returns only true or false, so just assess its return value, might as well subject that output to a ternary operator ...
Why make the code so hard to follow re-assigning the boolean value to 2 other variables?
PHP Code:
$bIsEmailValid = jValidateEmailUsingSMTP("$emailaddress", "REMOVED.com", "fraudcheck@REMOVED.com");
$emailchecker = $bIsEmailValid ? "Valid" : "Invalid";
if ($emailchecker=="Valid") {
// etc
}
There should be no need to quote a string argument which is a string ...
jValidateEmailUsingSMTP("$emailaddress", ....
This is a meaningless variable name, give it a name that means something, maybe you can do better than $update_flag?
Those 2 lines are exactly the same except for the EmailCheck value. Identify that which changes. Eradicate duplicate code when you can.
PHP Code:
$query3 = "UPDATE leads SET EmailCheck='PASS' WHERE LeadID='$leadid'";
} else {
$query3 = "UPDATE leads SET EmailCheck='FAIL' WHERE LeadID='$leadid'";
}
Lastly format your SQL statements using multiple lines like that and you will find that when you come back later to scan your code looking to solve a problematic SQL error, the SQL statements jump off the page at you - as opposed to just melding in with the PHP and other code.
These are arguably minor insignificant points, but taken together I find these practices make my code easier to read.
You and others may well not agree, and you are of course free to disagree or totally ignore me -- but having re-written so much of my own code since reading Bob Martins "Clean Code", I can't help but say something when I see so many instances in one place.
Maybe this helps you or not -- but hopefully it makes you think about getting the balance right between readability and springing to life unnecessary variables which just make your code harder to read and follow.
Bookmarks