Jump to content

Case insensitive PHP/MySQL queries


sasha.yee

Recommended Posts

Hi

 

I've been having a lot of trouble with just the tiny bit of following code:

$strNewEmail = strtoupper($strNewEmail);

$sql = "SELECT * FROM tblPartner_EmailSubscription WHERE UPPER(salesManagerEmail) LIKE '$strNewEmail' OR UPPER(salesContactEmail) LIKE '$strNewEmail';";
$result = @mysql_query($sql);
while ($row = @mysql_fetch_array($result)){
if ( ($row["SalesManagerEmail"] == $strNewEmail) ){
// sales contact added
$salesContactName = $row["SalesManager"];
@mysql_close($DatabaseConnection);
return "FAILED";
}else if ( ($row["SalesContactEmail"] == $strNewEmail) ){
// sales contact added
$salesContactName = $row["SalesContact"];
@mysql_close($DatabaseConnection);
return "FAILED";
}
}
return "PASS";

 

While I can punch the SQl query into PhpMyAdmin and get a result, if I try the script by itself it doesn't work as intended, coming up without any results for the query.

 

Could anyone please explain where I am going wrong?

 

Thanks

 

 

Sasha

 

Link to comment
Share on other sites

Thank you for the quick reply. I've removed the error suppressors, and added the check to see if anything is happening with the query, but to no avail.

 

I've just tested it then, and I've found that no matter the way that the form data is entered (it could be fake@email.com or FAkE@eMAil.cOm, or any variation of that) and it won't work.

Link to comment
Share on other sites

unfortunately CoolDude's suggestion did not return any errors.

 

If you would like to see the entire function, here it is.

 

function ValidateExistingEmail($strNewEmail){
global $salesContactName;

$DatabaseConnection = mysql_connect("mysql.imagine-hosting.com", "****", "****") or die(mysql_error());
mysql_select_db("netcomm", $DatabaseConnection) or die(mysql_error());
$strNewEmail = strtoupper($strNewEmail);

$sql = "SELECT * FROM tblPartner_EmailSubscription WHERE UPPER(salesManagerEmail) = '$strNewEmail' OR UPPER(salesContactEmail) = '$strNewEmail';";
$result = mysql_query($sql, $DatabaseConnection) or die(mysql_error());
while ($row = mysql_fetch_array($result)){
if ( ($row["SalesManagerEmail"] == $strNewEmail) ){
	    // sales contact added
            $salesContactName = $row["SalesManager"];
		mysql_close($DatabaseConnection);
		return "FAILED";
	}else if ( ($row["SalesContactEmail"] == $strNewEmail) ){
            // sales contact added
            $salesContactName = $row["SalesContact"];
            mysql_close($DatabaseConnection);
	return "FAILED";
	}
}
return "PASS";
}

 

The operators aren't going to do anything. As I said before, I tried this query in phpmyadmin, and there is no problem there. By substituting $strNewEmail for a value that I know is in the database, there is always a row of data returned.

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.