db_query returning blank page I've been stuck on this problem for a while now. I am trying to get the results to display from the api if there are no entries in the db that match the id thats being called from the api and then store those results into the db if there is a Id that matches then pull the results from the db and display them instead of displaying the results from the db.

I keep running into this error which is causing the page to go blank when being displayed PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column '29f1fc0bbd3dfe65a9e0ba6e044fb8e3398967a3' in 'where clause': SELECT * FROM {places} Where {ID} = 29f1fc0bbd3dfe65a9e0ba6e044fb8e3398967a3; I guess its because it cant find the id in the db, but it should still show the results from the api.

My logic makes sense im not sure what I am missing, Any suggestions?

       $listings_key = 'xxxxxxx';
            $xml = file_get_contents('https://maps.googleapis.com/maps/api/place/textsearch/xml?query=loans+near+'.$city_name.'&amp;sensor=true&amp;type=bank&amp;key='.$listings_key.'');
            $listings_request = simplexml_load_string($xml);

            $loans_places = '';
            $loans_places .= '&lt;div class="city-listings-wrapper"&gt;';

            foreach($listings_request-&gt;result as $pre_list){
                $xml2 = file_get_contents('https://maps.googleapis.com/maps/api/place/details/xml?reference='.$pre_list-&gt;reference[0].'&amp;sensor=true&amp;key='.$listings_key.'');
                $xml2 = simplexml_load_string($xml2);
                $l_ID = reset($xml2-&gt;result-&gt;id[0]);

                $dbresult = db_query("SELECT * FROM {places} Where {ID} = ".$l_ID."");      

                foreach($dbresult as $db_inlist){

                    dpr($db_inlist);

                    $places = array(
                        'Name'      =&gt; $xml2-&gt;result-&gt;name[0],
                        'Address'   =&gt; $xml2-&gt;result-&gt;adr_address[0],
                        'Phone'     =&gt; $xml2-&gt;result-&gt;formatted_phone_number[0],
                        'Website'   =&gt; $xml2-&gt;result-&gt;website[0],
                        'Ref_ID'    =&gt; $xml2-&gt;result-&gt;reference[0],
                        'ID'        =&gt; $xml2-&gt;result-&gt;id[0],
                        'City'      =&gt; ucwords(arg(2)),
                        'State'     =&gt; arg(1)
                    );


                    if($l_ID != $db_inlist-&gt;ID){ 
                        $loans_places .= '&lt;div class="city-listings"&gt;';
                        $loans_places .= '&lt;b&gt;'.$xml2-&gt;result-&gt;name[0].'&lt;/b&gt;&lt;/br&gt;';
                        $loans_places .= $xml2-&gt;result-&gt;adr_address[0].'&lt;/br&gt;';
                        $loans_places .= (isset($xml2-&gt;result-&gt;formatted_phone_number[0]) ? $xml2-&gt;result-&gt;formatted_phone_number[0].'&lt;/br&gt;' : '');
                        $loans_places .= (isset($xml2-&gt;result-&gt;website[0]) ? l('website', $xml2-&gt;result-&gt;website[0]).'&lt;/br&gt;' : '');
                        $loans_places .= '&lt;/div&gt;';

                        //execute store into db function
                        $nid = db_insert('places')-&gt;fields($places)-&gt;execute();

                    }else{
                        $loans_places .= '&lt;div class="city-listingsdb city-listings"&gt;';
                        $loans_places .= '&lt;b&gt;'.$db_inlist-&gt;Name.'&lt;/b&gt;&lt;/br&gt;';
                        $loans_places .= $db_inlist-&gt;Address.'&lt;/br&gt;';
                        $loans_places .= (isset($db_inlist-&gt;Phone) ? $db_inlist-&gt;Phone.'&lt;/br&gt;' : '');
                        $loans_places .= (isset($db_inlist-&gt;Website) ? l('website', $db_inlist-&gt;Website).'&lt;/br&gt;' : '');
                        $loans_places .= '&lt;/div&gt;';
                }
            }
        }

    $loans_places .= '&lt;/div&gt;';

return $loans_places;
You're currently escaping a bit too much...you only need to use the {} placeholders for table names. With an extra small change to protect you from SQL injection, your code should be something like:

$args = array(':id' =&gt; $l_ID);
$dbresult = db_query("SELECT * FROM {places} Where ID = :id", $args);