Funny mysql_query quirk with hyphenated email addresses

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
dandelion
Forum Newbie
Posts: 2
Joined: Sun Apr 25, 2010 12:10 pm

Funny mysql_query quirk with hyphenated email addresses

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Funny mysql_query quirk with hyphenated email addresses

Post by John Cartwright »

Double post.. why? :(

Locked.
Locked