sjk1000 Posted December 1, 2008 Share Posted December 1, 2008 Hi all I need to display and pass user-entered values of >= zero to the form handler from the script below. If the fields in the form are left blank, nothing should be displayed/passed. If I use >=0 in the IF statement, the blank values are displayed and are passed to the following page alongside the zeros (which are shown as zeros). Similarly, using ISSET. If I use !=0, the blanks are omitted (which is good) but, as you'd expect, so are the zeros. How do I filter out these non-zero values? I hope that makes sense. I don't have a full vocabulary for this yet. Any help is very much appreciated. Thanks, Steve { $qty=$_POST['qty']; $price=$_POST['price']; $shipping=$_POST['shipping']; $sdprice=$_POST['sdprice']; $productid=$_POST['productid']; print("<form action='http://www.mywebsite.co.uk/catalog/index.php?main_page=testbed' method='post'>"); print("<div class= 'divScroll-2'>"); print("<TABLE class='seller' ALIGN=center VALIGN=TOP width='850 '>\n"); print("<TR align=center><TH>Prod ID</TH><TH>Title</TH><TH>Qty</TH><TH>Price</TH><TH>Shipping</TH><TH>SD Price</TH></TR>"); for($x=0; $x<count($_POST['productid']); $x++) { if($qty[$x]!= 0||$price[$x] != 0||$shipping[$x] != 0||$sdprice[$x] != 0) { print("<TR><TD>" .$productid[$x]. " </TD><TD> " .query_get_product_name($productid, $x). "</TD><TD>".$qty[$x]."</TD><TD>" .$price[$x]. "</TD><TD>" .$shipping[$x]. "</TD><TD>" .$sdprice[$x]. "</TD></TR>"); } } print ("</TABLE>\n"); print ("</div>"); print ("<div style='float:right' > <input class='mybtn' SIZE='5' type='submit' name='confirm_db_update' value='Confirm'> </div>"); print ("</form>"); } Quote Link to comment https://forums.phpfreaks.com/topic/134984-solved-display-and-pass-values-0-and-filter-out-empty-fields/ Share on other sites More sharing options...
Mark Baker Posted December 1, 2008 Share Posted December 1, 2008 $qty=$_POST['qty']; if ($qty == '') { echo 'It isn't set'; // It's an empty string } else { echo 'It is set'; // It contains a string if (is_numeric($qty)) { $qty = intval($qty); // Convert it to a numeric value } else { echo 'Value in $qty is not a number'; } } Quote Link to comment https://forums.phpfreaks.com/topic/134984-solved-display-and-pass-values-0-and-filter-out-empty-fields/#findComment-702966 Share on other sites More sharing options...
sjk1000 Posted December 1, 2008 Author Share Posted December 1, 2008 This does it if($qty[$x]!= ''||$price[$x] != ''||$shipping[$x] != ''||$sdprice[$x] != '') Cheers, Steve Quote Link to comment https://forums.phpfreaks.com/topic/134984-solved-display-and-pass-values-0-and-filter-out-empty-fields/#findComment-702967 Share on other sites More sharing options...
sjk1000 Posted December 1, 2008 Author Share Posted December 1, 2008 Thanks for that Mark. You've sorted out something else I was puzzling over with the is_numeric too. Steve Quote Link to comment https://forums.phpfreaks.com/topic/134984-solved-display-and-pass-values-0-and-filter-out-empty-fields/#findComment-702969 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.