私は特に困惑している問題があります。電子メールアドレスの謎を使ったPHP/MySQL SELECTクエリ
PHPを使用してレコードセットをループし、電子メールアドレスが別のテーブルに存在するかどうかを確認しています。
コードは1つの特定の電子メールアドレスに到達するまでうまく動作し、私の人生にとって何が間違っているか見ることはできません。
メールアドレスは[email protected]です。次のエラーが表示されます。
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ambro'' at line 1
他のすべてのメールアドレスは問題ありません。
私は、クエリ
SELECT * FROM user_details WHERE email='[email protected]'
エコーとのNavicatでそれを実行すると、以下のように、それは
PHPコードを動作します:
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 FROM clients ORDER BY 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);
do {
/*Check table to see if email already exists*/
$query_check = sprintf("SELECT * FROM user_details WHERE 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 INTO 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);
を私が言ったように - このコードは動作しますが、それだけですこの1つの電子メールアドレスで照会しようとすると失敗します。
echo、try 'var_dump'とソース(Web環境の場合)を使用しないでください – ajreal
@Borealid - 興味深い。私は確かにそれを調べなければならないでしょう。 – Pandy
あなたのGetSQLValueString関数が間違っていることは言うまでもありません。 –