title: find and save variable in cookie
body: <p>I am trying to save variable in cookie and then retrieve it, so far i can save just a text and page url and then retrieve it where ever i want.</p>
  
  <p>Could u please help me out with it?for example in this code i want to save $room and $renthome values in cookie. </p>
  
  <p>this is my current code  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
     &lt;title&gt;New page string name&lt;/title&gt;
    &lt;link rel="stylesheet" href="css/reset.css"&gt; &lt;!-- Resource style --&gt;
  &lt;link rel="stylesheet" type="text/css" href="css/buy-rent.css" /&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"&gt;&lt;/script&gt;
    &lt;script&gt;
    function createCookie(name, value, days) {
      var expires = '',
      date = new Date();
      if (days) {
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = '; expires=' + date.toGMTString();
      }
      document.cookie = name + '=' + value + expires + '; path=/';
    }
    /*
    * Read cookie by name.
    * In your case the return value will be a json array with list of pages saved.
    */
    function readCookie(name) {
      var nameEQ = name + '=',
      allCookies = document.cookie.split(';'),
      i,
      cookie;
      for (i = 0; i &lt; allCookies.length; i += 1) {
        cookie = allCookies[i];
        while (cookie.charAt(0) === ' ') {
          cookie = cookie.substring(1, cookie.length);
        }
        if (cookie.indexOf(nameEQ) === 0) {
          return cookie.substring(nameEQ.length, cookie.length);
        }
      }
      return null;
    }
    /*
    * Erase cookie with name.
    * You can also erase/delete the cookie with name.
    */
    function eraseCookie(name) {
      createCookie(name, '', -1);
    }
  
    var faves = new Array();
  
    function isAlready(){
      var is = false;
      $.each(faves,function(index,value){
        if(this.url == window.location.href){
          console.log(index);
            faves.splice(index,1);
            is = true;
        }
      });
      return is;
    }
  
    $(function(){
      var url = window.location.href; // current page url
      $(document.body).on('click','#addTofav',function(e){
        e.preventDefault();
        var pageTitle = $(document).find("title").text();
        if(isAlready()){
        } else {
            var fav = {'title':pageTitle,'url':url};
            faves.push(fav);
        }
        var stringified = JSON.stringify(faves);
        createCookie('favespages', stringified);
        location.reload();
      });
  
  
       var myfaves = JSON.parse(readCookie('favespages'));
       if(myfaves){
         faves = myfaves;
       } else {
         faves = new Array();
       }
  
    });
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;a href="javascript:void(0);" id="addTofav"&gt;Add me to fav&lt;/a&gt;
    &lt;div class="img"&gt;
      &lt;div class="desc"&gt;
    &lt;ul id="appendfavs"&gt;
     
    &lt;/ul&gt;
    &lt;/div&gt;
    &lt;/div&gt;
  &lt;?php
  error_reporting(0);
  
  include("config.php");
  
  $quer= "SELECT*FROM ".$db_table." ";
  
  
  $query=mysqli_query($connect,$quer)
  or die(mysqli_error());
  ?&gt;
  
  &lt;?php while($row = mysqli_fetch_array($query)):
  $idhome= $row['idhome'];
  $room=$row['room'];
  $renthome=$row['renthome'];
  $pricehome=$row['pricehome'];
  ?&gt;
  
   &lt;?php endwhile;?&gt; 
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>