Skip to content Skip to sidebar Skip to footer

PHP Fatal Error: Call To Undefined Function Test_input() In C:\wamp\www\web\new9.php On Line 11

The following form shows an error on clicking the submit button if we enter the name only and submit.The error shown is Fatal error: Call to undefined function test_input() in C:

Solution 1:

Move your function out of your conditional if statement

It should be like this...

<?php
// define variables and set to empty values
$name1Err = $email1Err  =  "";
$name1 = $email1 =  "";

// Moved here
function test_input($data)
{
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}

if ($_SERVER["REQUEST_METHOD"] == "POST")
{
// .... your remaining code .......... !

From the PHP Docs...

When a function is defined in a conditional manner ... Its definition must be processed prior to being called.

Source


Solution 2:

In general, functions are parsed first and can therefore be used in any order.

echo foo();
function foo() {return "bar";}

The above works fine.

However, unlike some languages like JavaScript, PHP allows you to conditionally define functions. You might do something like this:

if( $something) {
    function foo() {echo "bar";}
}
else {
    function foo() {echo "fish";}
}
foo();

It's a bad thing to do (personally I'd prefer anonymous functions, or putting the conditional inside the function), but it's allowed.

However, doing this means that the functions can no longer be grabbed. They MUST be defined before they can be used. Going back to our first example:

if( true) {
    echo foo();
    function foo() {return "bar";}
}

This will fail.


Solution 3:

try

<form method='post' enctype='multipart/form-data' action='<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>'>

source:w3schools


Post a Comment for "PHP Fatal Error: Call To Undefined Function Test_input() In C:\wamp\www\web\new9.php On Line 11"