<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1038900" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1038900</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/webmasters-corner/pesky-session-add-id-url-adds-page-refresh#comment-1221426</link>
    <description> &lt;p&gt;Ok thanks, I have it sorted.&lt;/p&gt;
&lt;p&gt;I broke out of PHP to make the form, that way I could understand the sytnax better&lt;br /&gt;
And also will keep server usage down!&lt;/p&gt;
&lt;p&gt;For those interested, and others it may help, I&#039;ll explain what I did:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;	&amp;lt;form action=&amp;quot;session.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;	&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;check&amp;quot; value=&amp;quot;addpack&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;packadd&amp;quot; value=&amp;quot;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;echo &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;id&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; name=&amp;quot;submit&amp;quot; value=&amp;quot;Add to Cart&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;Because I have two other options for the users cart, remove one item and empty whole cart, I needed someway of tackling this altogether.&lt;/p&gt;
&lt;p&gt;So I used one page, sessions.php&lt;/p&gt;
&lt;p&gt;And to incoporate them all in one file I included in the form for the package add, delete and cart empty:&lt;/p&gt;
 </description>
     <pubDate>Mon, 09 Jul 2007 21:33:59 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1221426 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/webmasters-corner/pesky-session-add-id-url-adds-page-refresh#comment-1221419</link>
    <description> &lt;p&gt;I was wroking on seperate pages as you mentioned, but as I explained above, the $_GET[&#039;id&#039;] from the url is assigned to a variable, that variable is used within the cart contents and session calculations&lt;/p&gt;
&lt;p&gt;so the alternative I thought about is still have all the variables and cart session caclulations on the one page, as they were originaly, and change the link that users use to select the product they are choosing:&lt;br /&gt;
&#039;&lt;a href=&quot;yourcart.php?action=add&amp;amp;id=&amp;#039;.$row[&amp;#039;id&amp;#039;].&amp;#039;&quot;&gt;Add to cart&lt;/a&gt;&#039;;&lt;/p&gt;
&lt;p&gt;and maybe use a form?&lt;/p&gt;
&lt;p&gt;now forms are fairly straight forward, and i presume i would use hidden data to submit the variable value to the next page&lt;br /&gt;
where the next page would still have the get, but would now be $_GET[&#039;form_input_name&#039;]&lt;/p&gt;
&lt;p&gt;The products are listed into a table from the database in a standard loop&lt;br /&gt;
So the ID of the product is determined via the $row[&#039;id&#039;]&lt;br /&gt;
Each row has one product on it, the product is of course the [&#039;id&#039;]&lt;/p&gt;
&lt;p&gt;The bit i&#039;m stuck with, how do i put into a form something like:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;echo &amp;quot;&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;var1&amp;quot; value=&amp;quot;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php $_POST&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;.$row[&#039;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;]&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&amp;quot;&lt;/code&gt;&#039;&lt;/p&gt;
&lt;p&gt;cheers&lt;/p&gt;
 </description>
     <pubDate>Mon, 09 Jul 2007 20:03:09 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1221419 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/webmasters-corner/pesky-session-add-id-url-adds-page-refresh#comment-1221415</link>
    <description> &lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;Quote: So it doesnt know what that id was from the $_GET to display the required products&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;I thought that meant you wanted to get rid of the $action variable and keep the $id variable...so I&#039;m confused.&lt;/p&gt;
&lt;p&gt;Maybe it would be best to have the processing page separate from the cart page.  In other words, the link to add the product will go to like maybe add_item.php.  Then, redirect them to cart.php.&lt;/p&gt;
 </description>
     <pubDate>Mon, 09 Jul 2007 18:18:41 +0000</pubDate>
 <dc:creator>pr0gr4mm3r</dc:creator>
 <guid isPermaLink="false">comment 1221415 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/webmasters-corner/pesky-session-add-id-url-adds-page-refresh#comment-1221413</link>
    <description> &lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;&lt;strong&gt;pr0gr4mm3r;221410 wrote:&lt;/strong&gt; If you need to save one of the variables, then something like this would work.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;header&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;Location: cart.php?id=&#039; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_GET&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;id&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]); &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;erm&lt;br /&gt;
but that sends the id to the url&lt;br /&gt;
So I am back where I started, but now with another page inbetween&lt;br /&gt;
The point is to get to the cart to display the users cart contents without the ID=1 in the URL&lt;/p&gt;
 </description>
     <pubDate>Mon, 09 Jul 2007 18:09:57 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1221413 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/webmasters-corner/pesky-session-add-id-url-adds-page-refresh#comment-1221410</link>
    <description> &lt;p&gt;If you need to save one of the variables, then something like this would work.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;header&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;Location: cart.php?id=&#039; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_GET&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;id&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]); &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
 </description>
     <pubDate>Mon, 09 Jul 2007 17:56:24 +0000</pubDate>
 <dc:creator>pr0gr4mm3r</dc:creator>
 <guid isPermaLink="false">comment 1221410 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/webmasters-corner/pesky-session-add-id-url-adds-page-refresh#comment-1221409</link>
    <description> &lt;p&gt;hmm&lt;/p&gt;
&lt;p&gt;The problem i am having is the cart.php has ALL the code on it, all the variables everything&lt;/p&gt;
&lt;p&gt;So when the user clicks the link for the product they want, the whole workings from the $_GET to displaying products uses the same variables&lt;br /&gt;
So they all have to be on the same page&lt;/p&gt;
&lt;p&gt;And of course using your redirect does solve the problem as the id in the url was retrieved from a page, then that redirect sends them to display their cart&lt;br /&gt;
but then it doesnt recognise the variables that is assigned to the $_GET when it goes to the page to display their cart contents&lt;br /&gt;
So it doesnt know what that id was from the $_GET to display the required products&lt;/p&gt;
&lt;p&gt;The code i have doesnt simply $_GET then add to the session&lt;br /&gt;
otherwise i could simply get from the session on the next page&lt;br /&gt;
It uses a variable to perform a selection of possible actions&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;$product_id = $_GET[&amp;#039;id&amp;#039;];&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //the product id from the URL&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $action&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = $_GET[action]; //the action from the URL&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //if there is an product_id and that product_id doesn&amp;#039;t exist display an error message&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if($product_id &amp;amp;&amp;amp; !productExists($product_id)) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; die(&amp;quot;Error. Product Doesn&amp;#039;t Exist&amp;quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch($action) { &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case &amp;quot;add&amp;quot;:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $_SESSION[&amp;#039;cart&amp;#039;][$product_id]++; //add one to the quantity of the product with id $product_id&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case &amp;quot;remove&amp;quot;:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $_SESSION[&amp;#039;cart&amp;#039;][$product_id]--; //remove one item&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if($_SESSION[&amp;#039;cart&amp;#039;][$product_id] == 0) unset($_SESSION[&amp;#039;cart&amp;#039;][$product_id]); //if the quantity is zero, remove it completely to avoid quantity being -1, -2 etc upon further pressing of the link&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case &amp;quot;empty&amp;quot;:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unset($_SESSION[&amp;#039;cart&amp;#039;]); //empty the cart.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;So the code adds to the session but also gives the user the chance to remove items or empty all the cart&lt;br /&gt;
After that code it displays the cart, obviously using the session but also the variable $product_id and the options from the switch&lt;/p&gt;
&lt;p&gt;I dont know much about registering global variables? would this help, as I would only need it to remember $product_id&lt;br /&gt;
And will it remember the switch actions on another page?&lt;/p&gt;
&lt;p&gt;The other thing.&lt;br /&gt;
I am still learning, but isnt this a hellish way of doing things? :..&lt;/p&gt;
&lt;p&gt;The user clicks a link for a product. That link sends an ID to the URL, another page GETS the ID from the URL, then the script assigns the data from the GET to a variable, then it adds it to the session&lt;/p&gt;
&lt;p&gt;There surely must be a better way of doing all this&lt;br /&gt;
Cant i just assign the ID value to the required variable WHEN the user clicks the link?&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
 </description>
     <pubDate>Mon, 09 Jul 2007 17:51:37 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1221409 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/webmasters-corner/pesky-session-add-id-url-adds-page-refresh#comment-1221308</link>
    <description> &lt;p&gt;In your case, add this after your code that processes the addition of the item:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;header&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;Location: cart.php&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;That will clear the $_GET data and solve your problem.&lt;/p&gt;
 </description>
     <pubDate>Fri, 06 Jul 2007 17:54:36 +0000</pubDate>
 <dc:creator>pr0gr4mm3r</dc:creator>
 <guid isPermaLink="false">comment 1221308 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
