Page 1 of 1

Funny mysql_query quirk

Posted: Sun Apr 25, 2010 12:42 pm
by dandelion
Well this is the base Code:

Code: Select all

//Perform SQL query
			$query = sprintf("UPDATE  `db1`.`kundendaten` SET  `accepted` =  '1' WHERE  `kundendaten`.[b]`email` =  '%s' [/b]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 myPHPadmin directly with:

Code: Select all

UPDATE  `db1`.`kundendaten` SET  `accepted` =  '1' WHERE  `kundendaten`.`email` = [b] 'max-muster@hotmail.com[/b]' LIMIT 1;
...it works

2) If I change the query in my PHP Code to:

Code: Select all

//Perform SQL query
			$query = sprintf("UPDATE  `db1`.`kundendaten` SET  `accepted` =  '1' WHERE  `kundendaten`.[b]`email` =  'max-muster@hotmail.com' [/b]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:

Code: Select all

UPDATE  `db1`.`kundendaten` SET  `accepted` =  '1' WHERE  `kundendaten`.`email` = [b] 'max-muster@hotmail.com[/b]' LIMIT 1;
...but it does not work
...but if I copy and paste the echoed statement into a myPHPadmin 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

Posted: Sun Apr 25, 2010 3:08 pm
by requinix
What does

Code: Select all

echo bin2hex($email);
produce?