Jump to content

make 0 value not treated as empty value


bbmak

Recommended Posts

I have this validation of my form. However, the empty function treats all 0 as empty.  Are there anyway to make 0 as not an empty value?

if (empty($item_name) || empty($item_link) || empty($item_price))
{
$errors[] = 'Item Name, Item Link, and Item Price Cannot Be Empty.';
} else {

                  $validate = new validate();
                  if(!$validate->validateURL($item_link)) {
                  $errors[] = 'This is not a URL.';
                  }


                  if (!is_numeric($item_price)) {
                  $errors[] = 'Item Price Must be a number.';
                  }

       }

Link to comment
https://forums.phpfreaks.com/topic/267516-make-0-value-not-treated-as-empty-value/
Share on other sites

 

or you can use $item_name==''

if (!(isset($item_name)) || !(isset($item_link)) || !(isset($item_price)))
{
$errors[] = 'Item Name, Item Link, and Item Price Cannot Be Empty.';
} else {

                  $validate = new validate();
                  if(!$validate->validateURL($item_link)) {
                  $errors[] = 'This is not a URL.';
                  }


                  if (!is_numeric($item_price)) {
                  $errors[] = 'Item Price Must be a number.';
                  }

       }

Alliento has the best idea but use  logical == to compare for empty.


if ($item_name=='' || $item_link=='' || $item_price=='')
{
$errors[] = 'Item Name, Item Link, and Item Price Cannot Be Empty.';
} else {

                  $validate = new validate();
                  if(!$validate->validateURL($item_link)) {
                  $errors[] = 'This is not a URL.';
                  }


                  if (!is_numeric($item_price)) {
                  $errors[] = 'Item Price Must be 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.