Support » Fixing WordPress » how to clear and refresh a cookie

  • Hi there, I am trying to display records based on the value picked up with a button. The problem which I am facing is – on clicking one of the rows of html table i am picking up the value and store it in a cookie. And on the basis of this cookie displays other details in the second table. My format of the page is something like this :

    [ Table – 1 ]

    Button -> “View Selected Record”

    [ Table – 2 ]

    So the problem is : When I clicked on a row of a table-1, value is picked and store in a php variable ‘$ono’. Please see the code below :

    1.<?php
    2. $ono = isset($_COOKIE['sel_ordno']) ? $_COOKIE['sel_ordno'] : null;
    3. echo 'VAL :'.$ono;
    4. if(!empty($ono)){
    5. $selrec_query = "SELECT u.file_path, u.lbl_qty, u.lbl_prc, s.scat_name FROM utmp_orders as u join subcategory as s on s.scat_id = u.scat_id where u.t_ordid = {$ono}";
    6. $result = mysqli_query($connection, $selrec_query);
    7. }
    8.?>

    But, here on clicking the button nothing happens but when I refresh the page, value is shown in the second table. Why?

    I am unsetting the the cookie here. Please see the code below :

    1.<?php
    2.  if (isset($_COOKIE['sel_ordno'])){
    3.  unset($_COOKIE['sel_ordno']);
    4.  }
    5.?>

  • The topic ‘how to clear and refresh a cookie’ is closed to new replies.