0

I am checking to see if a value has been entered in a form and then updating only if a value is entered. The problem is I want 0 to be an option that can be entered and php is treating 0 as if it were the same as NULL which is the default entry in the DB so what I end up with is 0 entered in each column of the DB instead of empty values in some and numerical values in some.

Is there a way to check and see if a number including 0 has been entered and if not to treat the field as NULL?

if ($value != NULL ){
			
			//Update The Standing Order Amount
			$insert = "UPDATE custom_items SET AltQuantity='$value' WHERE VisitorID='$_SESSION[VisitorID]' AND ItemID='$item[id]'";
				 mysqli_query($dbc, $insert);
		    
			}

Thanks,
Eric

4
Contributors
3
Replies
6
Views
7 Years
Discussion Span
Last Post by Atli
0

!== The === and !== operators check type along with value. 0 is an integer, NULL is NULL. so $somevar = 0; if ($somevar == NULL) { /* true */ } but if ($somevar === NULL) { /*false*/ }

0

maybe you looking for this -

if(isset($_POST['submit_btn_name_in_your_form']) && $_POST['submit_btn_name_in_your_form']!='')
{
//now if the Quantity entered is 0 it will be entered in the db as '0'
$Quantity = $_POST['txtField_Quantity'];
//same for others too, if you want to escape blank (like setting $count ='' in the db)values from this,
this is called validation can be done with the javascript
$sql_query = "UPDATE custom_items SET AltQuantity='$Quantity' WHERE VisitorID='$_SESSION[VisitorID]' AND ItemID='$item[id]'"
}
0

Hey.

You could also do:

if(!empty($_POST['field']) || is_numeric($_POST['field'])) {
    // Do your thing.
}

// Or:
if(!empty($_POST['field']) || $_POST['field'] === '0') {
    // Do your thing.
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.