moracca Posted March 3, 2007 Share Posted March 3, 2007 ok, so the basic html is this (extraneous info taken out): <form name="add" action="<?=$PHP_SELF?>" method="post"> <?php while $row=mysql_fetch_array($result){ <<yadda yadda>> echo "<input type=\"text\" name=\"qty[" . $row['itemid'] . "]\">"; } ?> <input type="submit" name="add" value="add"> </form> Ok, so say there are 3 results, so therefore 3 qty inputs. When it gets posted back to the form, all 3 inputs get posted, even if they are empty. For example: session_start(); if ($_POST['add']){ echo "number of postqty items=" . count($_POST['qty']) . "<br>"; foreach ($_POST['qty'] as $id => $quant){ echo "value of this ids quant: " . $_POST['qty'][$id] . "<br>"; echo "id=$id<br>"; echo "quant=$quant<br>"; $_SESSION['cart'][$id] += $quant; echo "cartid=" . $_SESSION['cart'][$id]; echo "ONCE<br>"; } } will return: number of postqty items=3 value of this ids quant: 2 id=1 quant=2 cartid=2ONCE value of this ids quant: id=2 quant= cartid=0ONCE value of this ids quant: id=3 quant= cartid=0ONCE I want to only change the session variables if they input a quantity in the form. Any ideas? This is bothering me. Thanks! Link to comment https://forums.phpfreaks.com/topic/40945-solved-issue-with-posting-empty-form-variables/ Share on other sites More sharing options...
moracca Posted March 3, 2007 Author Share Posted March 3, 2007 I think I've sorted this one out. Needed an if (!empty()) statement in the for each loop. Thanks anyways. Link to comment https://forums.phpfreaks.com/topic/40945-solved-issue-with-posting-empty-form-variables/#findComment-198299 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.