PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
We're trying to send query statements into a function and then have it output the result as another function, to be used later on on the page, where we call the row info and all that.
It's for a register page- where users have to register an ID and password for login access. If the registration is succesful then the entry is added into my MySQL database.
function is_valid_input ($field)
{
echo '<br>'.$field.'<br>';
switch ($field)
{
case '$email' :
if (!eregi('^їa-zA-Z0-9_\-\.]+@їa-zA-Z0-9\-]+\.їa-zA-Z0-9\-\.]+$', $email))
{
echo 'That is not a valid email address. Please return to the previous page and try again.';
return true;
}
else
return false;
break;
case '$userID' :
if(!eregi('^ї0-9]$', $userID))
{
echo 'That is not a valid user ID. Please return to the previous page and try again.';
return true;
}
else
return false;
break;
}
}
is_valid_input('$email');
is_valid_input('$userID');
is_valid_input('$email'); .. that will pass in the literal string '$email' not the value of $email.
case '$email' :
if (!eregi('^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $email))
{
That wil check if the literal string '$email' was passed in then do an eregi on $email, which is never defined or brought into scope inside the function. I can see the problem but not sure which solution you need as the code is a little unclear, but i'm guessing you just need to pull the vars you are trying to validate into scope by putting global $email, $userID; at the top of the function.