简体   繁体   English

致命错误:调用未定义的函数

[英]Fatal error: Call to undefined function

I'm trying to validate a string that is entered into an input field on a form using a function defined in a javascript file that I am calling in the head tags, which is the first include in my index.php file. 我正在尝试使用我在head标签中调用的javascript文件中定义的函数来验证在表单的输入字段中输入的字符串,该文件是我的index.php文件中的第一个include。 There are a number of checks I am doing before calling the mod10() function which are all passing, but as soon as the mod10() function is called I get the following error: 在调用mod10()函数之前,我要进行大量检查,但都通过了,但是一旦调用mod10()函数,我就会收到以下错误:

Fatal error: Call to undefined function mod10() in /Applications/XAMPP/xamppfiles/htdocs/modderfc/Content/new_registration.php on line 46 致命错误:在第46行的/Applications/XAMPP/xamppfiles/htdocs/modderfc/Content/new_registration.php中调用未定义函数mod10()

Here is the block of code where the error is being thrown: 这是引发错误的代码块:

//Check if the ID Number entered is a valid ID Number
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $fieldTitle = "Player ID Number";
    if (empty($_POST["player_id_number"])) {
        $player_id_numberErr = $fieldTitle . $requiredErrorText;
    } else {
        // check if the ID Number entered is a valid ID Number
        if (mod10($player_id_number,13) == FALSE) {           //line 46
            $player_id_numberErr = $id_numberValidationErrorText;
        } else {
            $player_id_number = test_input($_POST["player_id_number"]);
        }
    }
}

I tried setting the $player_id_number field as well using the following before the if (mod10($player_id_number,13) == FALSE) { line link this: 我尝试在if(mod10($ player_id_number,13)== FALSE){行链接之前使用以下命令设置$ player_id_number字段:

$player_id_number = test_input($_POST["player_id_number"]);

but that results in the same error, which is the same line it is failing as before: 但这会导致相同的错误,它与以前一样是失败的同一行:

Fatal error: Call to undefined function mod10() in /Applications/XAMPP/xamppfiles/htdocs/modderfc/Content/new_registration.php on line 47 致命错误:在第47行的/Applications/XAMPP/xamppfiles/htdocs/modderfc/Content/new_registration.php中调用未定义函数mod10()

For reference I have also included the function in the .js file: 作为参考,我还在.js文件中包含了该函数:

function mod10(num, validLength) {  
if (num == "" || num == null) return true;
var valid = "0123456789"; 
var sCCN = num.toString().replace (/ /g,''); 
var len = sCCN.length;  
var iCCN = parseInt(sCCN,10);
var iTotal = 0;  // integer total set at zero
var bResult = false;  
var temp;  // temp variable for parsing string
var calc;  // used for calculation of each digit

for (var j=0; j<len; j++) {
    temp = "" + sCCN.substring(j, j+1);
    if (valid.indexOf(temp) == "-1"){bResult = false;}
}

if(len != validLength) {
      bResult = false;
}
else
{  // num is proper length - let's see if it is a valid mod10 number

    for (var i=len;i>0;i--) {               // LOOP throught the digits 
          calc = parseInt(iCCN,10) % 10;    // right most digit
          calc = parseInt(calc,10);         // assure it is an integer
          iTotal += calc;                   // running total of the number as we loop - Do Nothing to first digit
          i--;                              // decrement the count - move to the next digit
          iCCN = iCCN / 10;                 // subtracts right most digit 
          calc = parseInt(iCCN,10) % 10 ;   // NEXT right most digit
          calc = calc *2;                   // multiply the digit by two

          switch(calc){
            case 10: calc = 1; break;       //5*2=10 &amp; 1+0 = 1
            case 12: calc = 3; break;       //6*2=12 &amp; 1+2 = 3
            case 14: calc = 5; break;       //7*2=14 &amp; 1+4 = 5
            case 16: calc = 7; break;       //8*2=16 &amp; 1+6 = 7
            case 18: calc = 9; break;       //9*2=18 &amp; 1+8 = 9
            default: calc = calc;           //4*2= 8 &amp;   8 = 8  -same for all lower numbers
          }                 

        iCCN = iCCN / 10;  // subtracts right most digit 
        iTotal += calc;  // running total of the number as we loop

      }  // END OF LOOP

    bResult =  iTotal%10 == 0 // check to see if the sum Mod 10 is zero

    }
return bResult; // Return the results

} }

It is important to understand the difference between client side code and server side code. 了解客户端代码和服务器端代码之间的区别很重要。 the PHP (server side) will run first, and generate html (and JavaScript if you wish), and the browser will load the output of that process. PHP(服务器端)将首先运行,并生成html(如果需要,还可以生成JavaScript),然后浏览器将加载该过程的输出。

from that point you are in the client side and have front end tools such as JavaScript at your disposal. 从那时起,您就在客户端,可以使用JavaScript之类的前端工具。

if you wish to call a JavaScript function from php you can echo the JavaScript code in the page in a <script> section, but that code will only run after the browser loads the page. 如果您希望从php调用JavaScript函数,则可以在<script>部分中回显页面中的JavaScript代码,但是该代码仅在浏览器加载页面后运行。 the php will not actually run that function, just print it as text. php实际上不会运行该功能,只是将其打印为文本。

if you wish to to access the server code from the client side you can use AJAX. 如果您希望从客户端访问服务器代码,则可以使用AJAX。

You are mixing php with javascript here. 您在这里将php与javascript混合使用。 Php will never be able to execute your mod10 function because it's written in JS. Php将永远无法执行您的mod10函数,因为它是用JS编写的。 Plain answer: Recode your mod10 function in php. mod10 :在php中重新编码您的mod10函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:调用未定义函数FusionCharts() - Fatal error: Call to undefined function FusionCharts() 致命错误:未捕获错误:调用未定义函数loginRelocate()Javascript - Fatal error: Uncaught Error: Call to undefined function loginRelocate() Javascript PHP致命错误:调用未定义函数esc_url() - PHP Fatal error: Call to undefined function esc_url() Codeigntier / AJAX-致命错误:调用未定义函数form_input() - Codeigntier/AJAX - Fatal error: Call to undefined function form_input() in Grunt-致命错误未定义不是函数 - Grunt - Fatal error undefined is not a function 如何修复 php 致命错误:未捕获错误:调用未定义的 function nm_blog_get_ajax_content()? - How to fix this fatal error of php Fatal error: Uncaught Error: Call to undefined function nm_blog_get_ajax_content()? 使用PHP创建登录页面:致命错误:未捕获错误:调用未定义函数mysql_connect() - Create login page using PHP: Fatal error: Uncaught Error: Call to undefined function mysql_connect() Wordpress:致命错误:调用未定义的函数wp_get_current_user() - Wordpress: Fatal error: Call to undefined function wp_get_current_user() 致命错误:在1861行上调用ajaxCRUD.class.php中的未定义函数q() - Fatal error: Call to undefined function q() in ajaxCRUD.class.php on line 1861 SetForm致命错误:未被捕获的错误:调用未定义的方法PHPMailer :: SetForm() - SetForm Fatal error: Uncaught Error: Call to undefined method PHPMailer::SetForm()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM