Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can i select values on mysql table using cookie
    primarykey
    data
    text
    <p>How can i select values on mysql table using cookie?</p> <p>I wanted to select values on mysql table depending on a cookie.</p> <p>I have this query,</p> <pre><code> 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 &gt;= 0.0000 and p.expires_date &gt; 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); </code></pre> <p>The cookie is set on <code>header.php</code> file,</p> <pre><code>&lt;?php if(!empty($_POST['country'])) { $country = strtolower($_POST['country']); setcookie("country", $country, time()+604800, '/'); // cookie expires in 7 days. } ?&gt; </code></pre> <p>I call the query in <code>index.php</code>.</p> <p>Say, the <code>$_COOKIE['country']</code> is set to <code>168</code> I wanted to select values <code>WHERE s.countries_id = '168'</code> </p> <p>However, the cookie output is blank.. so it becomes <code>WHERE s.countries_id = ''</code> thats why there are no values returned. </p> <p>I need to find a way to use cookie on the <code>WHERE</code> clause</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload