PHP / MySQL SELECT query using email address mystery -
i have particularly puzzling problem.
i using php loop through recordset , identify if email address exists in table.
the code works fine until gets 1 particular email address , can't life of me see wrong.
the email address marcodambrosio@domain.com. following error:
you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'ambro'' @ line 1
all other email address fine.
i echo query
select * user_details email='marcodambrosio@domain.com'
and run in navicat , works
php code follows:
if (!function_exists("getsqlvaluestring")) { function getsqlvaluestring($thevalue, $thetype, $thedefinedvalue = "", $thenotdefinedvalue = "") { if (php_version < 6) { $thevalue = get_magic_quotes_gpc() ? stripslashes($thevalue) : $thevalue; } $thevalue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($thevalue) : mysql_escape_string($thevalue); switch ($thetype) { case "text": $thevalue = ($thevalue != "") ? "'" . $thevalue . "'" : "null"; break; case "long": case "int": $thevalue = ($thevalue != "") ? intval($thevalue) : "null"; break; case "double": $thevalue = ($thevalue != "") ? doubleval($thevalue) : "null"; break; case "date": $thevalue = ($thevalue != "") ? "'" . $thevalue . "'" : "null"; break; case "defined": $thevalue = ($thevalue != "") ? $thedefinedvalue : $thenotdefinedvalue; break; } return $thevalue; } } /*get source data*/ mysql_select_db($database, $link); $query_clients = "select email clients order client_id desc"; $clients = mysql_query($query_clients, $link) or die(mysql_error()); $row_clients = mysql_fetch_assoc($clients); $totalrows_clients = mysql_num_rows($clients); { /*check table see if email exists*/ $query_check = sprintf("select * user_details email=%s",getsqlvaluestring($row_clients['email'],"text")); echo "<br>".$query_check."<br>"; $check = mysql_query($query_check, $link) or die(mysql_error()); if (mysql_num_rows($check)==0) { $query_insertusers = sprintf("insert users (username, password, userlevel) values (%s, %s, 1)", $username, $password); echo $query_insertusers."<br>"; //$insertusers = mysql_query($query_insertusers, $link) or die(mysql_error()); } } while ($row_clients = mysql_fetch_assoc($clients)); mysql_free_result($clients);
as said - code works, when trying query 1 email address fails.
this looks escaping going wrong somehow: right syntax use near 'ambro''
seems indicate e-mail might marcod'ambrosio@domain.com
. if
echo "<br>".$query_check."<br>";
and run that in navicat, have same error?
Comments
Post a Comment