简体   繁体   English

从数据库收到的错误为#1064-PHP和MySQL

[英]Error received from database was #1064 - PHP & MySQL

I have a simple MySQL query that I use in PHP but it gives me this error; 我有一个在PHP中使用的简单MySQL查询,但它给了我这个错误。

Database query failed. 数据库查询失败。 Error received from database was #1064: You have an error in your SQL syntax; 从数据库收到的错误是#1064:您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL' at line 3 for the query: SELECT * FROM mantis_user_table WHERE email LIKE '%me%'. 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第3行的查询中在'NULL'附近使用:SELECT * FROM mantis_user_table WHERE email like'%me%'。

 $t_user_table = db_get_table( 'mantis_user_table' );   
 $temp_mail = '%' . $p_email . '%';
 $query = "SELECT * FROM $t_user_table WHERE email LIKE '{$temp_mail}'";
 $result = db_query_bound( $query, Array( $p_realname ) );

The thing I can not understand is, when I run it in phpmyadmin, it gives me the correct values. 我无法理解的是,当我在phpmyadmin中运行它时,它为我提供了正确的值。 So can you please help me with this situation ? 那么,您能帮我解决这种情况吗?

Thank you 谢谢

EDIT : 编辑:

This is the code that I use while editing : 这是我在编辑时使用的代码:

$File = "c:/YourFile.txt";
$Handle = fopen($File, 'w');
$Data = $query;
fwrite($Handle, $Data);
fclose($Handle);

Here you can see the query that I get when I write : 在这里,您可以看到编写时得到的查询:

SELECT * FROM mantis_user_table WHERE email LIKE '%meh%'

And this query normally gives me some results in phpmyadmin , now I dont have any result on web site 这个查询通常会在phpmyadmin中给我一些结果,现在我在网站上没有任何结果

And if you want this is the rest of the code that returns the id of the selected item: 如果需要,剩下的代码将返回所选项目的ID:

$result = db_query_bound( $query, Array( $temp_mail ) );
if( 0 == db_num_rows( $result ) ) {
    return false;
} else {
    $row = db_fetch_array( $result );
    user_cache_database_result( $row );
    return $row['id'];
}

try making 尝试制作

$query = 'SELECT * FROM $t_user_table WHERE email LIKE "{$temp_mail}"'; 

(some versions of mysql don't recognize ' symbol) (某些版本的mysql无法识别'符号)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM