PHP - Am I calling a function correctly? -
here code:
$oldphone = $_post["phone"]; $newphone = makeinteger($oldphone); lengthmustbe($newphone, 10, "please enter valid 10-digit phone number.");
here function:
function lengthmustbe($str, $length, $errormsg) { if (strlen($str) != $length) { $status = "failure"; $error = $errormsg; } };
the function pretty self explanatory..
when try pass "123", 10, "not long enough"
, $status still "success" (defined @ top of page.)
you need set $status
variable like:
$tmparray = lengthmustbe($newphone, 10, "please enter valid 10-digit phone number."); $status = $tmparray[0]; $statusmsg = $tmparray[1];
and function:
function lengthmustbe($str, $length, $errormsg) { if (strlen($str) != $length) { return array("failure", $errormsg); } else { return array("success", ""); } }
don't use globals terrible idea...
Comments
Post a Comment