在PHP中调用未定义的函数消息

时间:2014-01-15 05:42:52

标签: php mysql

我目前正在关注如何使用MySQL和php创建登录系统的书籍教程但是在尝试选择一个县之后我收到以下错误消息(如果你去{{你可以看到自己的错误信息] 3}}然后点击

RegistrationPage.php:

Fatal error: Call to undefined function is_valid_county() in /home/cs12jkk/public_html/register-process.php on line 34

//这是注册过程页面上的第34行:

if (isset($_POST['county']) && $_POST['county'] != "") {
    if(!is_valid_county($_POST['county'])) {
        $_SESSION['error'][] = "Please choose a valid county";
    }
}

这是我在 validation.inc页面

中的功能
function is_valid_county($county) {
    $validCounties = array ( "Avon","Bedfordshire","Berkshire","Borders","Buckinghamshire","Cambridgeshire","Central","Cheshire","Cleveland","Clwyd","Cornwall","County Antrim","County Armagh","County Down","County Fermanagh","County Londonderry","County Tyrone","Cumbria","Derbyshire","Devon","Dorset","Dumfries and Galloway","Durham","Dyfed","East Sussex","Essex","Fife","Gloucestershire","Grampian","Greater Manchester","Gwent","Gwynedd County","Hampshire","Herefordshire","Hertfordshire","Highlands and Islands","Humberside","Isle of Wight","Kent","Lancashire","Leicestershire","Lincolnshire","Lothian","Merseyside","Mid Glamorgan","Norfolk","North Yorkshire","Northamptonshire","Northumberland","Nottinghamshire","Oxfordshire","Powys","Rutland","Shropshire","Somerset","South Glamorgan","South Yorkshire","Staffordshire","Strathclyde","Suffolk","Surrey","Teesside","Tyne and Wear","Warwickshire","West Glamorgan","West Midlands","West Sussex","West Yorkshire","Wiltshire","Worcestershire",);
    if (in_array($county,$validCounties)) {
            return true;
    } else {
            return false;
    }
} //end function is_valid_county

2 个答案:

答案 0 :(得分:0)

通过查看代码,is_valid_county方法应位于同一页面上:

if (isset($_POST['county']) && $_POST['county'] != "") {
    if(!is_valid_county($_POST['county'])) {
        $_SESSION['error'][] = "Please choose a valid county";
    }
}

function is_valid_county($county) {
    // your code here
}

稍后,在编辑代码时,您的函数位于validation.inc中 因此,您需要在页面上包含它:

include_once("validation.inc.php");

if (isset($_POST['county']) && $_POST['county'] != "") {
    if(!is_valid_county($_POST['county'])) {
        $_SESSION['error'][] = "Please choose a valid county";
    }
}

答案 1 :(得分:-1)

首先在您的注册页面中包含validation.inc页面,然后输入您的代码

include_once("validation.inc.php");

if (isset($_POST['county']) && $_POST['county'] != "") {
    if(!is_valid_county($_POST['county'])) {
        $_SESSION['error'][] = "Please choose a valid county";
    }
}