Problem with Variables
Posted: Thu Aug 14, 2008 6:21 pm
I have an include full of functions to validate form data.
I pass information to the function - Great..
Returning information (such as an error code) isn't working for me.. Dunno why.
Example: record2.php
Example: inc.funct.valid.php
This is a really dumbed down version of my script.. however the problem lies in the function PHNCHK. When an error is thrown (improper format) my variable "$errmsg" isn't being passed through the functions return statement.. Why?
I pass information to the function - Great..
Returning information (such as an error code) isn't working for me.. Dunno why.
Example: record2.php
Code: Select all
include ('includes/inc.funct.valid.php');
foreach (array_keys($_POST) as $key)
{
switch ($_POST[$key])
{
case "Phone";
$$key = $_POST[$key];
PHNCHK('primary phone', $_POST[$key], 'text');
break;
...
}
$$key = $_POST[$key];
}
Code: Select all
function PHNCHK ($field, $challenge, $type)
{
$position = strpos($challenge, "-");
if ($position === false)
{
$errmsg = 1;
echo "Your $field is formatted improperly. Format: ###-###-####.";
return $errmsg;
}
if ($pos === 3) //###-...
{
... // left out to shorten script
}
else
{
return;
}
}