Page 1 of 1

Funny mysql_query quirk with hyphenated email addresses

Posted: Sun Apr 25, 2010 12:45 pm
by dandelion
Well this is the base Code:
//Perform SQL query
$query = sprintf("UPDATE `db1`.`kundendaten` SET `accepted` = '1' WHERE `kundendaten`.`email` = '%s' LIMIT 1;", $email);
$query = sprintf($query);
mysql_query($query) or die ('Query failed: ' . mysql_error());

This works...
....with "normal" Email addresses ($email) like hobo@hobo.com...
...but with hyphenated Email addresses like max-muster@hotmail.com it does not work. (mind the dash / hyphen / minus)

I did some testing:

1) If I query mysql with PHPMyAdmin directly with:
UPDATE `db1`.`kundendaten` SET `accepted` = '1' WHERE `kundendaten`.`email` = 'max-muster@hotmail.com' LIMIT 1;
...it works

2) If I change the query in my PHP Code to:
//Perform SQL query
$query = sprintf("UPDATE `db1`.`kundendaten` SET `accepted` = '1' WHERE `kundendaten`.`email` = 'max-muster@hotmail.com' LIMIT 1;");
$query = sprintf($query);
mysql_query($query) or die ('Query failed: ' . mysql_error());
...it works

3) If I echo ($query) from my base Code (at the top) with the $email = "max-muster@hotmail.com" it echoes:
UPDATE `db1`.`kundendaten` SET `accepted` = '1' WHERE `kundendaten`.`email` = 'max-muster@hotmail.com' LIMIT 1;
...but it does not work
...but if I copy and paste the echoed statement into a PHPMyAdmin query...it does work.

FUNNY QUIRK. It really drives me nuts.
Seems like it's not a MYSQL issue but some kind of PHP issue.

I spent the whole day searching for an answer but couldn't find any.

Hope someone can help me with this one. It's a tough nut to crack.

Re: Funny mysql_query quirk with hyphenated email addresses

Posted: Sun Apr 25, 2010 1:11 pm
by John Cartwright
Double post.. why? :(

Locked.