for a textfield that asks for a number amount to be entered and is does not have parameter set to it, when i put an “if statement” requiring information to be entered do i put
@Stephen_PhilbinJun 13.2005 — #When dealing with zero as an integer it's often best to use the strict equality operator. Using === rather than == means that the variable or value you are comparing is of the same type as well as value as the other value or variable. So ===0 checks the value being compared is an integer too and === FALSE checks that the value being compared is a boolean value too.
So 0 == FALSE is true, but 0 === FALSE is not true.
Also 0 == "0" is true, but 0 === "0" is not true.
If 0 is recieved as a value from a form it is considered a string value. (that being the "0" version). If 0 is put between " or ' marks it is considered a string (text), but if it is a number on its own, it is considered an integer (a mathematical object that can be used in a mathematical way).
Does that make sense of should I ramble incoherrantly a bit more?
@xredawg909xauthorJun 14.2005 — #my C++ background sorta helps me understand, but just incase i think the incoherent rambling should help. maybe i didn't explain clearly... say i'm asking a current bank balance (text field) , they leave it blank and hit submit and in my php code i didn't set it to $bal(double or float)
and i want them to go back and enter a value for their balance if they left it blank
would my if statement look like if($bal == 0){please go back and enter missing field} or if($bal==false){please go back and enter missing field} ? or would it be single "= " ? been a while since i've taken c++ so sorry if i seem a little slow here =)
@xredawg909xauthorJun 14.2005 — #coo thanx that resposnse hit the mark just one more question, if i have multiple values i don't want empty or 0 would it be if(empty($bal) || empty($variable2) || " " ||) ?
@NogDogJun 14.2005 — #The example you gave is a bit weird, with the third clause being just a space character and ending with a "||", but in theory, yes, you could do: [code=php] if(empty($var1) || empty($var2) || empty($var3)) { # error } else { # all required variables populated with non-zero values } [/code] Here's an algorithm I've used sometimes: [code=php] # required fields in format input_id => description: $required = array("field1" => "Field One", "field3" => "Field Three", "field5" => "Field Five"); # initialize error message: $error = ""; # check each required field: foreach($required as $key => $val) { if(empty($_POST[$key])) { $error .= "<p>ERROR: You must enter a value for $val.</p>n"; } } if(!empty($error)) { echo $error; } else { # proceed with processing of form... } [/code]
@xredawg909xauthorJun 15.2005 — #this php code looks similar to c++ would i be able to apply the same basic principles if i wanted to make a custom code?