0

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);
1
  • you should just look at the error message if a query 'doesn't work'. Commented Apr 23, 2014 at 12:50

2 Answers 2

1

You need to add single quotes around your PHP variable, so the updated code:

 $row = Db_DbHelper::query("select subject from system_email_templates where id = '".$email_id."'");
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer, but it still doesn't seem to work. I tried placing double quotes around single quotes (which is an opposite of what you've done) and it also doesn't work.
0

Try this,

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

2 Comments

no, which is the strange thing. I checked the error log and it's clear
Well echo query and run it to your mysql tool,check query is ok.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.