Php 如何使用cookie在mysql表上选择值

Php 如何使用cookie在mysql表上选择值,php,mysql,Php,Mysql,如何使用cookie在mysql表上选择值 我想根据cookie选择mysql表上的值 我有这个疑问, function db_prepare_input($string) { if (is_string($string)) { return trim(stripslashes($string)); } elseif (is_array($string)) { reset($string);

如何使用cookie在mysql表上选择值

我想根据cookie选择mysql表上的值

我有这个疑问,

    function db_prepare_input($string)
    {
        if (is_string($string)) {
            return trim(stripslashes($string));
        } elseif (is_array($string)) {
            reset($string);
            while (list($key, $value) = each($string)) {
                $string[$key] = tep_db_prepare_input($value);
            }
            return mysql_real_escape_string($string);
        } else {
            return mysql_real_escape_string($string);
        }
    }
    $country_id = db_prepare_input($_COOKIE['country']);

    $catglobal_sql = "select p.*, case when p.specials_new_products_price >= 0.0000 and p.expires_date > Now() and p.status != 0 then p.specials_new_products_price else p.products_price end price from " . TABLE_GLOBAL_PRODUCTS . " p INNER JOIN ".TABLE_STORES." s ON s.blog_id = p.blog_id where MATCH (p.products_name,p.products_description) AGAINST ('%".$search_key."%') OR p.products_name like '%".$search_key."%' and s.countries_id = '".$country_id."' and p.display_product = '1' and p.products_status = '1' ".$duration." order by p.products_date_added DESC, p.products_name";
    $catglobal_1     = mysql_query($catglobal_sql);
cookie设置在
header.php
文件上

<?php
if(!empty($_POST['country'])) 
{ 
 $country = strtolower($_POST['country']); 
 setcookie("country", $country, time()+604800, '/'); // cookie expires in 7 days.
}
?>

我在
index.php
中调用查询

比如说,
$\u COOKIE['country']
被设置为
168
我想选择值
其中s.countries\u id='168'

但是,cookie输出为空。。所以它变成了
其中s.countries\u id='
,这就是没有返回值的原因


我需要找到一种在
WHERE
子句中使用cookie的方法

运行查询时会发生什么?它会给出一个错误吗?拉错数据?echo$catglobal\u sql;这是您所期望的吗?您没有在上面显示的代码中运行查询。我已经更新了代码和我的帖子。如果您使用硬编码值替换$\u COOKIE['country'],是否有效?