That's how the database works
It seems quite likely you're using MySQL, and what you're describing is simply how it works:
mysql> select * from posts where id = 1;
+----+-----------+------------------------+---------------------+----------+
| id | title | body | created | modified |
+----+-----------+------------------------+---------------------+----------+
| 1 | The title | This is the post body. | 2013-08-01 07:34:57 | NULL |
+----+-----------+------------------------+---------------------+----------+
1 row in set (0.00 sec)
mysql> select * from posts where id = "1and this text";
+----+-----------+------------------------+---------------------+----------+
| id | title | body | created | modified |
+----+-----------+------------------------+---------------------+----------+
| 1 | The title | This is the post body. | 2013-08-01 07:34:57 | NULL |
+----+-----------+------------------------+---------------------+----------+
1 row in set, 1 warning (0.00 sec)
With input like that, the database will cast the value to an integer before performing a query.
If you want to prevent your application from treating those two user inputs as the same - you'll need to validate user input and make sure it's numeric before using it.