Note that there are some explanatory texts on larger screens.

plurals
  1. POForm data not Posting for later PHP processing
    primarykey
    data
    text
    <p>Hello I am a first time poster. I tried searching for an answer, but nothing really obvious popped out at me from the material already posted. I need another pair of eyes on this, as I cannot figure out why my form data isn't posting.</p> <p>I am making a shopping cart using session variables to store data short term. Ultimately, during checkout, this order data will be finalized to a database. When I render my shopping cart contents for review, I need to provide my customers the freedom to update quantity (or delete). Keeping this as uncluttered as possible, here is the html rendering of the cart contents (without headings, totals, etc):</p> <pre><code>&lt;form action="mas_cart.php" method="post"&gt; &lt;table id="shCart" border="1" width="800px" cellspacing="0"&gt; &lt;tr&gt; &lt;td align="left"&gt;DSC0679&lt;/td&gt; &lt;td align="left"&gt;7.2H x 11W Glossy Paper &lt;/td&gt; &lt;td align="center"&gt;No&lt;/td&gt;&lt;td align="center"&gt;$55&lt;/td&gt; &lt;td align="center"&gt; &lt;input id="inp_qty" type="text" name="DSC0679_unsigned_7.2H x 11W Glossy Paper $55" value="1" size="3"&gt; &lt;/td&gt; &lt;td align="right"&gt;55.00&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt;MRS5293&lt;/td&gt; &lt;td align="left"&gt;7.3H x 11W Glossy Paper &lt;/td&gt; &lt;td align="center"&gt;Yes&lt;/td&gt; &lt;td align="center"&gt;$55&lt;/td&gt; &lt;td align="center"&gt; &lt;input id="inp_qty" type="text" name="MRS5293_signed_7.3H x 11W Glossy Paper $55" value="1" size="3"&gt; &lt;/td&gt; &lt;td align="right"&gt;55.00&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt;MRS5293&lt;/td&gt; &lt;td align="left"&gt;7.3H x 11W Glossy Paper &lt;/td&gt; &lt;td align="center"&gt;No&lt;/td&gt; &lt;td align="center"&gt;$55&lt;/td&gt; &lt;td align="center"&gt; &lt;input id="inp_qty" type="text" name="MRS5293_unsigned_7.3H x 11W Glossy Paper $55" value="2" size="3"&gt; &lt;/td&gt; &lt;td align="right"&gt;110.00&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="hidden" name="save" value="true"/&gt; &lt;input type="image" src="images/save-changes.png" style="border:1px solid rgb(50,50,50)" alt="Save Changes"/&gt; &lt;/form&gt; </code></pre> <p>And here is the PHP code which is supposed to process updates:</p> <pre><code>//update section if(isset($_POST['save'])) { foreach ($_SESSION['cart'] as $item =&gt; $qty) { if($_POST[$item]==0 || $_POST[$item]=="") { unset($_SESSION['cart'][$item]); } else { $_SESSION['cart'][$item] = $_POST[$item];} } </code></pre> <p>In execution, <code>$_POST['save']</code> is properly set, but <code>$_POST[$item]</code> returns undefined index:</p> <blockquote> <p>Notice: Undefined index: DSC0679_unsigned_7.2H x 11W Glossy Paper $55 in C:\xampp\htdocs\aaa\mas_cart.php on line 57</p> <p>Notice: Undefined index: MRS5293_signed_7.3H x 11W Glossy Paper $55 in C:\xampp\htdocs\aaa\mas_cart.php on line 57</p> <p>Notice: Undefined index: MRS5293_unsigned_7.3H x 11W Glossy Paper $55 in C:\xampp\htdocs\aaa\mas_cart.php on line 57</p> </blockquote> <p>Basically, the conditional in post processing always renders as true, since the index is undefined, so updating spits out errors and clears the cart. I know it is hateful asking someone else to look at my code, but I am having the very worst time figuring this out. Any suggestions would be greatly appreciated! Help?</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.
 

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