Note that there are some explanatory texts on larger screens.

plurals
  1. POform keeps adding value a to session array on refresh?
    primarykey
    data
    text
    <p>i have a form on a page with a hidden input with the name of a book and a submit button i use to add the book name to an an arry contanined in the $_SESSION array. each time the user clicks on the button the name of the book is added to the array contained in the session.this works fine. the main problem is when i refresh the page it the name of the book to the array again without me pressing the "add to cart button" i can see why this is happening as when i send the value to the array in an if statement i make sure and unset() the submit button. here is the code for the php part.</p> <pre><code> &lt;?php if(isset($_SESSION['username'])) { if(!isset($_SESSION['itemnames'])) { $itemnames = array(); $_SESSION['itemnames'] = $itemnames; echo "&lt;p&gt;second if&lt;/p&gt;"; } if (isset($_GET['submit1'])) { $name = $_GET['book1']; $_SESSION['itemnames'][]= $name ; unset($_GET['submit1']); echo "&lt;p&gt;" . var_dump($_SESSION['itemnames']) . "&lt;/p&gt;"; } } ?&gt; </code></pre> <p>and here is my form i also have another form on the page and im wondering if this is causing the problem i dont think so at the moment.</p> <pre><code>&lt;form method="get" action="" name="myform"&gt; &lt;span style="color:#000"&gt; &lt;label for="quantity"&gt;Quantity:&lt;/label&gt; &lt;/span&gt; &lt;select name="quantity" id="quantity"&gt; &lt;option value="1" selected&gt;1&lt;/option&gt; &lt;option value="2"&gt;2&lt;/option&gt; &lt;option value="3"&gt;3&lt;/option&gt; &lt;option value="4"&gt;4&lt;/option&gt; &lt;option value="5"&gt;5&lt;/option&gt; &lt;option value="6"&gt;6&lt;/option&gt; &lt;option value="7"&gt;7&lt;/option&gt; &lt;option value="8"&gt;8&lt;/option&gt; &lt;option value="9"&gt;9&lt;/option&gt; &lt;option value="10"&gt;10&lt;/option&gt; &lt;option value="11"&gt;11&lt;/option&gt; &lt;option value="12"&gt;12&lt;/option&gt; &lt;option value="13"&gt;13&lt;/option&gt; &lt;option value="14"&gt;14&lt;/option&gt; &lt;option value="15"&gt;15&lt;/option&gt; &lt;option value="16"&gt;16&lt;/option&gt; &lt;option value="17"&gt;17&lt;/option&gt; &lt;option value="18"&gt;18&lt;/option&gt; &lt;option value="19"&gt;19&lt;/option&gt; &lt;option value="20"&gt;20&lt;/option&gt; &lt;option value="21"&gt;21&lt;/option&gt; &lt;option value="22"&gt;22&lt;/option&gt; &lt;option value="23"&gt;23&lt;/option&gt; &lt;option value="24"&gt;24&lt;/option&gt; &lt;option value="25"&gt;25&lt;/option&gt; &lt;option value="26"&gt;26&lt;/option&gt; &lt;option value="27"&gt;27&lt;/option&gt; &lt;option value="28"&gt;28&lt;/option&gt; &lt;option value="29"&gt;29&lt;/option&gt; &lt;option value="30"&gt;30&lt;/option&gt; &lt;/select&gt; &lt;input type="hidden" name="book1" value="cape clear island: its peopleand landscape" /&gt; &lt;input type="submit" value="Add To Cart" name="submit1"&gt; &lt;/button&gt; &lt;/form&gt; </code></pre> <p>i cant think why refreshing the page will add one to my array! im adding the name numerous time just to test will the multiple clicks work. thanks for your help in advance! obviously ill be doing other stuff with the dropdown list when i get this part working. what i basically have is a submit button on a page that i should be able to click multiple times to add a book to a session array depending on how many times i want to add the book to the cart this will increment a counter at the top of the page depending on how many times the item is clicked. i just dont want the book to increment in the session array when i refresh. so the add item to cart button does not redirect the user to the cart im going to have a seperate button to "view cart" if you get what im trying to do here. </p>
    singulars
    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.
 

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