Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do my session variables unset when I don't call the href that unsets it
    primarykey
    data
    text
    <p>In my PHP program I have a few links that all link to the same page. What it does is update the current site depending on my action and I send new information through a GET or if I need to unset my session. </p> <p>In one link to the same page, I am calling unset($_SESSION['search']) and in the other I am calling a GET for sorting information. But when I call the GET link and not the unset link, my session variable gets reset anyways.</p> <p>Everything is being done in view.php</p> <p>Here is my unset link</p> <pre><code>&lt;a href="view.php&lt;?php unset($_SESSION['search']); ?&gt;"&gt;View All&lt;/a&gt; </code></pre> <p>My GET link(s)</p> <pre><code>&lt;th&gt;&lt;a href="view.php?id=&lt;?php echo 'id';?&gt;"&gt;ID&lt;/a&gt;&lt;/th&gt; &lt;th&gt;&lt;a href="view.php?id=&lt;?php echo 'itemName';?&gt;"&gt;Item Name&lt;/a&gt;&lt;/th&gt; &lt;th&gt;&lt;a href="view.php?id=&lt;?php echo 'description';?&gt;"&gt;Description&lt;/a&gt;&lt;/th&gt; &lt;th&gt;&lt;a href="view.php?id=&lt;?php echo 'supplierCode';?&gt;"&gt;Supplier&lt;/a&gt;&lt;/th&gt; &lt;th&gt;&lt;a href="view.php?id=&lt;?php echo 'cost';?&gt;"&gt;Cost&lt;/a&gt;&lt;/th&gt; </code></pre> <p>When I call the unset link, I need it to reset the session variable. But when I call the get links, I need to keep the session variable. </p> <p>What can I do to make that happen?</p> <p>My php action when calling those links</p> <pre><code>if (isset($_SESSION['search'])) { $sql_query = "SELECT * FROM inventory WHERE description LIKE '%".$_SESSION['search']."%' ORDER BY ".$id." ASC"; $check = true; } else if ($_POST &amp;&amp; !(Trim($_POST['search']) === '')) { $search = $link-&gt;real_escape_string($_POST['search']); $_SESSION['search'] = $search; $sql_query = "SELECT * FROM inventory WHERE description LIKE '%".$_SESSION['search']."%' ORDER BY ".$id." ASC"; $check = true; } else { $sql_query = "SELECT * FROM inventory ORDER BY ".$id." ASC"; } </code></pre> <p>Because the $_SESSION['search'] is always reset whenever I redirect back to view.php, the last else is always called when I press the get links even though I need it to stay!</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.
 

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