spectreon666 Posted January 16, 2008 Share Posted January 16, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86295-solved-code-error/ Share on other sites More sharing options...
cooldude832 Posted January 16, 2008 Share Posted January 16, 2008 well where you get the template() function from??? Quote Link to comment https://forums.phpfreaks.com/topic/86295-solved-code-error/#findComment-440850 Share on other sites More sharing options...
spectreon666 Posted January 16, 2008 Author Share Posted January 16, 2008 what do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/86295-solved-code-error/#findComment-440852 Share on other sites More sharing options...
Lamez Posted January 16, 2008 Share Posted January 16, 2008 he means where do you define what template() does? Do you have any includes or is it in the rest of the code. Quote Link to comment https://forums.phpfreaks.com/topic/86295-solved-code-error/#findComment-440854 Share on other sites More sharing options...
adam291086 Posted January 16, 2008 Share Posted January 16, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86295-solved-code-error/#findComment-440855 Share on other sites More sharing options...
spectreon666 Posted January 16, 2008 Author Share Posted January 16, 2008 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() Quote Link to comment https://forums.phpfreaks.com/topic/86295-solved-code-error/#findComment-440862 Share on other sites More sharing options...
adam291086 Posted January 16, 2008 Share Posted January 16, 2008 There are going to be a number of errors. Post your whole code. I can tell already because what you have on line 8 is wrong Quote Link to comment https://forums.phpfreaks.com/topic/86295-solved-code-error/#findComment-440865 Share on other sites More sharing options...
spectreon666 Posted January 16, 2008 Author Share Posted January 16, 2008 <?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'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86295-solved-code-error/#findComment-440871 Share on other sites More sharing options...
revraz Posted January 16, 2008 Share Posted January 16, 2008 Need a semi colon after include include 'includes.php'; <--- Quote Link to comment https://forums.phpfreaks.com/topic/86295-solved-code-error/#findComment-440873 Share on other sites More sharing options...
adam291086 Posted January 16, 2008 Share Posted January 16, 2008 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'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86295-solved-code-error/#findComment-440875 Share on other sites More sharing options...
spectreon666 Posted January 16, 2008 Author Share Posted January 16, 2008 Yeah thats perfect...thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/86295-solved-code-error/#findComment-440879 Share on other sites More sharing options...
spectreon666 Posted January 16, 2008 Author Share Posted January 16, 2008 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/86295-solved-code-error/#findComment-440985 Share on other sites More sharing options...
cooldude832 Posted January 16, 2008 Share Posted January 16, 2008 you can only declare a function once, redefining it causes an error. Quote Link to comment https://forums.phpfreaks.com/topic/86295-solved-code-error/#findComment-440989 Share on other sites More sharing options...
spectreon666 Posted January 16, 2008 Author Share Posted January 16, 2008 How do i fix it in the above forms Quote Link to comment https://forums.phpfreaks.com/topic/86295-solved-code-error/#findComment-440994 Share on other sites More sharing options...
adam291086 Posted January 16, 2008 Share Posted January 16, 2008 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') } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86295-solved-code-error/#findComment-440999 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.