By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,426 Members | 3,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,426 IT Pros & Developers. It's quick & easy.

not able to compare & fetch data from table using where clause

P: 34
Hi,

i am building a small forum site as my final year project & stuck in a very trivial problem.

I have a table which are varchar type of data & i am trying to fetch data from table based on some condition.

$query = 'select reply_Id, post_Id, replied_by, reply, date_of_reply from reply_info where reply_info.post_Id ='. $x;

as $x='pi_1';

here $x has string value & post_Id in table has varchar value & has the same value (for that column in table) as given to $x, but still this query execution is failing. it returns false for result.

Now if i dont give any where clause query fetches all the rows of table. I tried this to confirm if connection to data base is working fine.

this is really urgent..i have already wasted an hour in this :-(

thanks in advance.
Mar 22 '09 #1
Share this Question
Share on Google+
1 Reply


Markus
Expert 5K+
P: 6,050
There's nothing that sticks out at me, other than that IDs are generally stored as integers. Are you positive it's a VARCHAR?

When you're developing something, you should be debugging it. So, use mysql_error() if a query fails, to see why it failed.

Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT * FROM `tbl1` WHERE 1";
  2. $query_result = mysql_query( $query ) or die ( mysql_error() );
  3.  
As soon as the query is stored in $query_result, if there's an error, your page will die with the cause of the error displayed, e.g. 'tbl1 doesn't exist'.
Mar 22 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.