简体   繁体   English

SQL查询不接受PHP变量

[英]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; 我只是想用一个代替整数值的PHP变量运行SQL查询,但是它似乎不起作用; when I replace the variable with a simple number (like 1 ) it actually works, so there's nothing wrong with the query itself. 当我用一个简单的数字(如1 )替换变量时,它实际上可以工作,因此查询本身没有错。

When I put in the variable $email_id at the end, it does not work. 当我将变量$email_id放在最后时,它不起作用。

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);

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

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