0

Can you please help me on below query?

php code://

$countdate='2017-01-03';
$countsql='SELECT rucid,"databaseType","countLoggedOn","prodCount","nprodCount","countType" FROM "ru_countLog" WHERE "countLoggedOn"=$countdate';

--> It's giving syntax error

syntax error at or near "$" LINE 1: ...untType" FROM "ru_countLog" WHERE "countLoggedOn"=$countdate

1
  • syntax error at or near "$" LINE 1: ...untType" FROM "ru_countLog" WHERE "countLoggedOn"=$countdate Commented Jan 4, 2017 at 10:02

2 Answers 2

1

Remove the internal double quotes from your query:

$countsql = "SELECT rucid, databaseType, countLoggedOn,
             prodCount, nprodCount, countType
             FROM ru_countLog
             WHERE countLoggedOn = $countdate";

Note that this query is vulnerable to SQL injection. Consider parametrizing $countdate. With http://php.net/manual/en/function.pg-query-params.php, this would become

$countsql = 'SELECT rucid, databaseType, countLoggedOn,
         prodCount, nprodCount, countType
         FROM ru_countLog
         WHERE countLoggedOn = $1';

$result = pg_query_params($dbconn, $countsql, array($countdate));

where $dbconn is your database connection

Sign up to request clarification or add additional context in comments.

1 Comment

$countdate will not be interpreted in your first code sample, as it's within a single-quoted string.
0

Maybe you should try like this

$countdate='2017-01-03';
$countsql='SELECT rucid,"databaseType","countLoggedOn","prodCount","nprodCount","countType" FROM "ru_countLog" WHERE "countLoggedOn"='.$countdate;

Hope this help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.