Jump to content

[SOLVED] Code error


spectreon666

Recommended Posts

Im getting this error

 

 

 

Fatal error: Call to undefined function template() in E:\Other\xampp\htdocs\bookingformprocess.php on line 18

 

if ($error) {

// form data is invalid, redisplay form with error message from its template

template('http://localhost/bookingform.tpl.php'); ----> line 18

 

Im new to programming so im learning just unsure how to fix the above error...thanks in advance

 

 

 

 

Link to comment
Share on other sites

you are trying to call on a function in your script. If you haven't defined what that function does then you script wont work. Hence the reason why you are getting the error

Fatal error: Call to undefined function template() in E:\Other\xampp\htdocs\bookingformprocess.php on line 18

 

this is where you call on the function

 

template('http://localhost/bookingform.tpl.php');

 

we need to see the function you created unless you haven't created it, which explains everything

Link to comment
Share on other sites

I think its sorted...you mean

 

include 'includes.php' ---- I just stuck it in so its not getting an error on that line any more.

 

Parse error: syntax error, unexpected T_IF---> I am however getting this error now on line 8 -->

 

if (!isset($_POST['name']) or empty($_POST['name']) ) // !ctype_alpha()

Link to comment
Share on other sites

 

 

<?php /// bookingformprocess.php

include 'includes.php'

 

 

 

if (!isset($_POST['name']) or empty($_POST['name']) )

 

$error = 'You need to enter your name!';

 

else {

$name = $_POST['name'];

}

 

 

if ($error) {

// form data is invalid, redisplay form with error message from its template

template('localhost/bookingform.tpl.php');

}

 

else {

// save to database, and display a result page

include('saveform.php');

$confirmationMessage = 'Booking data saved';

template('formresult.tpl.php');

}

 

?>

Link to comment
Share on other sites

try this

 


<?php /// bookingformprocess.php
include 'includes.php';



if (!isset($_POST['name'])) 

$error = 'You need to enter your name!'; 

else {
   $name = $_POST['name'];
}


if ($error) {
   // form data is invalid, redisplay form with error message from its template
   template('localhost/bookingform.tpl.php');
} 

else {
   // save to database, and display a result page
   include('saveform.php');
   $confirmationMessage = 'Booking data saved';
   template('formresult.tpl.php');
}

?>

Link to comment
Share on other sites

Im getting another error now when it reads the above form

 

Fatal error: Cannot redeclare template() (previously declared in E:\Other\xampp\htdocs\includes.php:3) in E:\Other\xampp\htdocs\includes.php on line 8

 

heres the includes.php

 

<?php

function template($tpl)

{

ob_start();

include $tpl;

echo ob_get_clean();

}    -----> line 8

 

?>

 

 

 

Link to comment
Share on other sites

You dont seem to know what you are doing with function ect so lets keep in simple.

 


if (!isset($_POST['name'])) 

$error = 'You need to enter your name!'; 

else {
   $name = $_POST['name'];
}

if ($error) {
   // form data is invalid, redisplay form with error message from its template
header('Location: the name of the form goes here')
} 

else {
   // save to database, and display a result page
   include('saveform.php');
   $confirmationMessage = 'Booking data saved';
   header('Location: the name of the success form goes here')
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.