# Query works when hardcoded, but not when a number is concatenated

**URL:** <https://forum.kirupa.com/t/query-works-when-hardcoded-but-not-when-a-number-is-concatenated/174205>\
**Category:** programming\
**Created:** [January 3, 2006, 7:44pm UTC](https://forum.kirupa.com/t/query-works-when-hardcoded-but-not-when-a-number-is-concatenated/174205 "2006-01-03T19:44:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaDeViL](https://avatars.discourse-cdn.com/v4/letter/d/a9a28c/32.png) [@DaDeViL](https://forum.kirupa.com/u/DaDeViL)\
**Post date:** [January 3, 2006, 7:44pm UTC](https://forum.kirupa.com/t/query-works-when-hardcoded-but-not-when-a-number-is-concatenated/174205/1 "2006-01-03T19:44:21Z")

</div>

Hello, I am trying to make a CMS where queries are actually held in an html file (for specific reasons)

Anyway, when this html file is called the id that the query needs is stored in a tag like this: \<!id\>

Well the CMS converts that tag to a number, like 1.

I can concatenate the number to a query and plug it into the mysql\_query  
function, but in this case it gives me a  
“Warning: mysql\_fetch\_object(): supplied argument is not a valid MySQL result resource in /home/unidenti/www/test/UiCMS/php/sql.inc.php on line 47”

If i dont concatenate it and hardcode the number 1 into the query, the query works!

I have no idea why it behaves this way! Please help!

## Link:

You will see the error on [This Page](http://test.un-identified.com/UiCMS/realIndex.php?page=Events) when you click **View Comments**

## Code below:

In the HTML file the php is defined like this:

```auto

...
<---- HTML ---->
...
<?php 

$id = "<!id>"; // <----the <id> tag is replaced by 1
//---Initialize MySql Connection Class---
$config = new config();
$sql2 = new sql($config->dbhost,$config->dbuser,$config->dbpass, $config->dbname);
$sql2->_select_db($config->dbname);
//---------------------------------------------

$comment_query ='SELECT DISTINCT cms_comments.PK_comments, cms_users.user_name,cms_comments.comment_title,cms_comments.comment,cms_comments.comment_date FROM cms_comments, cms_users WHERE cms_comments.FK_event = ' . $id ;
		
echo $comment_query;	
$result_query =$sql2->_query($comment_query);

while($result = $sql2->_fetch_object($result_query)){
...						
}

?>

```

Thanks!
