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



我目前正在关注有关如何使用 MySQL 和 php 创建登录系统的书籍教程,但是在尝试选择一个县后收到以下错误消息(如果您转到 cs12jkk.icsnewmedia.net 然后单击

注册页面.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";
    }
}

这是我在验证.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

通过查看您的代码,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";
    }
}

首先像这样在你的注册页面中包含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";
    }
}

最新更新