Forum Moderators: coopster

Message Too Old, No Replies

Fatal Error

Call to undefined function

         

jessyfryer

8:29 pm on Jan 2, 2015 (gmt 0)

10+ Year Member



When attempting to make a fully validated form application on one page, I am presented with the error

Fatal error: Call to undefined function validate_forename() in /home/public_html/COMM2735/example/forms/formapp.php on line 21

This is the code I've entered, line 21 is in bold.

<?php
//SET ALL VARIABLES TO EMPTY
$forename = $surname = $telephone = $email = $dob = $university = "";
$message = "";

//CAPTURE FORM DATA, IF ANYTHING WAS SUBMITTED
if (isset($_POST['forename']) and ($_POST['forename'] != ''))
$forename = clean_string($db_server, $_POST['forename']);
if (isset($_POST['surname']) and ($_POST['surname'] != ''))
$surname = clean_string($db_server, $_POST['surname']);
if (isset($_POST['telephone']) and ($_POST['telephone'] != ''))
$surname = clean_string($db_server, $_POST['telephone']);
if (isset($_POST['email']) and ($_POST['email'] != ''))
$surname = clean_string($db_server, $_POST['email']);
if (isset($_POST['dob']) and ($_POST['dob'] != ''))
$surname = clean_string($db_server, $_POST['dob']);
if (isset($_POST['university']) and ($_POST['university'] != ''))
$surname = clean_string($db_server, $_POST['university']);

//VALIDATE EACH VARIABLE, BUILDING A MESSAGE AS WE GO
$message = validate_forename($forename);
$message .= validate_surename($surename);
$message .= validate_telephone($telephone);
$message .= validate_email($email);
$message .= validate_dob($dob);
$message .= validate_university($university);

//DISPLAY A MESSAGE
if ($message) {
$message = "<p><strong>Details not yet submitted
successfully:</strong></p>$message";
}else{
$message = "<h1>Details submitted successfully - You are now registered at Example Company!</h1>";
$message .= "<p>";
$message .= "Forename: $forename<br />";
$message .= "Surname: $surname<br />";
$message .= "Telephone number: $telephone<br />";
$message .= "Email address: $email<br />";
$message .= "Date of Birth: $dob<br />";
$message .= "University: $university<br />";
$message .= "</p>";

}
?>

<!DOCTYPE html>
<html>
<head>
<title>Registration</title>
</head>
<body>
<h1>Register for access to a huge database of Second Hand University Books</h1>
<p><strong>Please fill out the form below and submit the following details:</strong></p>
<form id="frmSimple" action="" method="post">
<div style="text-align:right;float:left;font-size:medium;margin-right:10px;">
Forename:&nbsp;<input type="text" id="forename" name="forename" /><br />
Surname:&nbsp;<input type="text" id="surname" name="surname" /><br /><br />
Date of Birth:&nbsp;<input type="text" id="dob" name="dob" /><br /><br />
Telephone Number:&nbsp;<input type="text" id="telephone" name="telephone" /><br />
Email Address:&nbsp;<input type="text" id="email" name="email" /><br /><br />
University:&nbsp;<input type="text" id="university" name="university" /><br /><br />
<input type="submit id="submit" name="submit" />
</div>
<div style="clear:all" />
</form>
<?php echo $message; ?>
</body>
</html>



Thanks for any help given!

[edited by: coopster at 5:22 pm (utc) on Jan 15, 2015]
[edit reason] exemplified the domain [/edit]

lucy24

9:24 pm on Jan 2, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Odd. I'd have homed in on the next line:

$message = validate_forename($forename);
$message .= validate_surename($surename);


Is that copy-and-paste, or did you retype?

jessyfryer

9:27 pm on Jan 2, 2015 (gmt 0)

10+ Year Member



I copy and pasted it in, I thought at first that it was because there was a missing . before the = but even when I included this it stayed the same.

Habtom

9:31 pm on Jan 2, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there another file you should "include" to the same file?

penders

9:58 pm on Jan 2, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



As Habtom says, there must be another file that contains these validation functions...? (They are not built-in PHP functions.)

You are calling a function named validate_forename() and you have not defined this function in the code you have posted, hence the fatal error "Call to undefined function".

It's quite possible that validate_surename(), validate_telephone(), etc. will all result in the same error(?) but it is failing on the first one.

It has nothing to do with the missing period (string concatenation operator). (In fact, I would include the period for consistency, since you are initialising the variable at the start of your script.)

Note that there are other inconsistencies/errors in your script... $surname / $surename. Assigning multiple values to $surname. validate_surename() - is that correct?

lucy24

10:47 pm on Jan 2, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I thought at first that it was because there was a missing . before the =

As long as you keep the lines in the same order, it doesn't matter.
= here means "the variable 'message' is defined as blahblah"
and then
.= means "the variable 'message' is redefined as whatever-it-was-before plus this new stuff"

Since you've taken the precaution of pre-defining "message" as "" you will readily see that there's no difference.

penders, the bit that jumped out at me was "surename" where "surname" seemed to be expected. But if none of the "blahblah_validate" functions have been defined* then I guess it doesn't matter, because the php will fall into a terminal coma the first time it meets anything it can't handle.


* Since I don't speak php, I checked the online manual and came up ice cold.

penders

11:18 pm on Jan 2, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



penders, the bit that jumped out at me was "surename" where "surname" seemed to be expected. ....


Yes, the
$surename
variable is an "error", but this would just result in a "Notice: Undefined variable" (if error_reporting is set to report E_NOTICE messages) and the code would continue to run.
validate_surename()
certainly looks like another fatal error, although we don't know for sure from the code given (but it should be corrected regardless). However, as you suggest, the compiler is failing on the preceding
validate_forename()
call and is unable to proceed further (terminal coma) until this first ("fatal") problem is fixed.