捕获到的异常'Exception',消息为'您的SQL语法有错误

问题描述 投票:0回答:1

当用户首次登录站点时,我在索引页面上收到此错误。之后,在用户注销并再次登录之前,不会跟踪任何错误。

错误是:

    [29-Nov-2019 05:46:54 Asia/Tehran] PHP Fatal error:  Uncaught exception 'Exception' with message 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'and p_payment IS NOT NULL and p_refid > 99' at line 1 query: SELECT * FROM admin_accounts where nationalcode =  and p_payment IS NOT NULL and p_refid > 99' in /home/example.com/config/MysqliDb.php:1819
Stack trace:
#0 /home/example.com/config/MysqliDb.php(1427): MysqliDb->_prepareQuery()
#1 /home/example.com/config/MysqliDb.php(513): MysqliDb->_buildQuery(NULL)
#2 /home/example.com/user/index.php(245): MysqliDb->query('SELECT * FROM a...')
#3 /home/example.com/user/index.php(40): pay_status('')
#4 {main}
  thrown in /home/example.com/config/MysqliDb.php on line 1819

索引页的第40行是:

if (pay_status($code)){echo 'something';}

和索引页的第245行:

    function pay_status($code){
    $db = getDbInstance();
    $paid = $db->query ('SELECT * FROM admin_accounts where code= '.$code.' and p_payment IS NOT NULL and p_refid > 99');
    if (count ($paid) > 0){
            return true;
        }else{
            return false;
        }
}
php
1个回答
-1
投票

如果表列code是nvarchar(字符串类型),那么您应该添加单个cort(')

$paid = $db->query ('SELECT * FROM admin_accounts where code= \''.$code.'\' and p_payment IS NOT NULL and p_refid > 99');

$paid = $db->query ("SELECT * FROM admin_accounts where code= '".$code."' and p_payment IS NOT NULL and p_refid > 99");
© www.soinside.com 2019 - 2024. All rights reserved.