Image

Imagepatchwolf wrote in Imagephp

Listens: Metallica - One

Output Validation?

Hi guys,

I'm wondering if it's possible to validate the output of an sql query?

I have the following query/code (using PHP5, and MSSQL):

$sql = "SELECT TOP 100 PERCENT Mem_Number, Title_1, Name_1, Surname_1, Email, Date_Sent_Renewal, EmailList, Renewal_Date FROM BTCMembers WHERE (DATEDIFF(d, Renewal_Date, GETDATE()) > ".$cutoff.") AND (DATEDIFF(d, Renewal_Date, Date_Sent_Renewal) < 0) AND (Email <> '') AND (Date_Sent_Renewal <> '') AND (EmailList = 1) ORDER BY Mem_Number ASC";

$result = odbc_exec($contact, $sql); // Run the query


Now this query works exactly as I expect it to, but some of the data which is pulled could cause minor problems later.

Specifically, there are a few records which have an "Email" field value of "N/A" -- the fault of dodgy input validation, I know, but I didn't make the input interface. *shrug*

So, is there a way to write the query so that data pulled from the Email column must make a regular expression valid for email addresses?

Posted to Imagephp, Imagesqlserver, and Imagemysql