Jump to content

[SOLVED] display and pass values >=0 and filter out empty fields


sjk1000

Recommended Posts

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>");
}

$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';

  }

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.