简体   繁体   中英

sql query not accepting a php variable

I feel a little guilty about posting this because I posted a similar but different question before, but I couldn't figure out what the problem with this one is.

I am simply trying to run a SQL query with a PHP variable taking place of an integer value, but it doesn't seem to work; when I replace the variable with a simple number (like 1 ) it actually works, so there's nothing wrong with the query itself.

When I put in the variable $email_id at the end, it does not work.

Can anyone point out what the problem might be?

Code:

$row = Db_DbHelper::query('select subject from system_email_templates where id = '.$email_id);

您需要在PHP变量周围添加单引号,因此更新后的代码为:

 $row = Db_DbHelper::query("select subject from system_email_templates where id = '".$email_id."'");

Try this,

    $sql = "select subject from system_email_templates where id = '".$email_id."' ";
    $row = Db_DbHelper::query($sql);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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