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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -