Hi All, I am generating one query dynamically in php, that query looks like this "SELECT sum(a.premium_amt), c.base_premium FROM policy_holders a, policy_status b, ins_plans c WHERE a.login_date <= '$lastDate' AND b.ph_id = a.ph_id AND b.issued_date <= '$issue' AND b.ph_status = 2 AND a.ro_id = '".$ro_id."' AND programecode = 4 AND a.policy_name = ".$policy_row['0']." AND c.plan_id = a.policy_name" when i am echoing the query it is showing that query, if i copy that query and run in phpmyadmin it is producing good and correct results. But if i run the same query by using mysql_query function it is giving null values. if you remove a.ro_id = '".$ro_id."' or programecode = 4 or b.ph_id = a.ph_id From that query then it is running perfectly in mysql_query function. But i need to have those conditions. If you need any clarification regarding my problem ping me in gtalk at(phanikrishna @ webkuteer.com) Thanks in Advance.
does your b.ph_id = a.ph_id need to be b.ph_id = 'a.ph_id' try changing a.ro_id = '".$ro_id."' to a.ro_id = '$ro_id' and change programecode = 4 to programecode = '4'
I am not getting any error to use mysql_error function. It is returning NULL values. i done the changes said by orionoreo but, still the errors remain same. Thank you,
OK I would do the following firstly you do this one " some text '".$somevariable."' some more text " PHP: I would do it 'some text "'.addslashes($somevariable).'" Some more text'; PHP: note: i swapped the ' with " and added a function to prevent errors in the query Then I would try this one. $sql = 'YOUR QUERY GOES HERE'; echo $sql; $query = mysql_query($sql); PHP: That way you can simply echo the query and check to see that the query is OK and that the variables had the propper values. Hope this helps.