Page 1 of 1
Including Functions
Posted: Fri Aug 08, 2008 3:49 pm
by Zzarkc-20
Hey, I'm having trouble including functions. I'm writing a function to check input from a form, and to return data from that... Here's my syntax:
Code: Select all
file1.php
<?php
include('functions.php');
if ( $_POST ){
$fail = ordercheck( $_POST );
}
?>
functions.php
<?php
function ordercheck( $_POST ){
CODE HERE...
return $fail;
}
?>
Now, when I check file1.php, it comes up with this on the screen:
Parse error: syntax error, unexpected $end in /path/functions.php on line 64
Where's my problem? Thanks!
Re: Including Functions
Posted: Fri Aug 08, 2008 4:01 pm
by EverLearning
Post the contents of functions.php file.
Re: Including Functions
Posted: Fri Aug 08, 2008 4:14 pm
by Zzarkc-20
Code: Select all
<?php
function ordercheck( $_POST ){
$fail = false;
if ( filter_has_var( INPUT_POST, "fname" ) ) {
$_POST["fname"]="";
$fail=true;
}
--MORE IFS--
if ( $fail == false ){
if (!isset($_POST["shipping"])){
$_POST["shipping"] = "No";
}
return $fail;
}
?>
I got rid of the html skeleton because it wasn't making a difference in the error, and I like less clutter on the page. I'm not sure if that could be a source though (I've tried with both combinations).
Re: Including Functions
Posted: Fri Aug 08, 2008 4:26 pm
by EverLearning
You're missing closing curly bracket to an if statement
Code: Select all
if ( $fail == false ){
if (!isset($_POST["shipping"])){
$_POST["shipping"] = "No";
}
should be
Code: Select all
if ( $fail == false ){
if (!isset($_POST["shipping"])){
$_POST["shipping"] = "No";
}
}
Re: Including Functions
Posted: Fri Aug 08, 2008 4:33 pm
by Zzarkc-20
That was it. I can't believe it was that lame of a problem... *Smacks self in head*
Anyway, thanks again.
Re: Including Functions
Posted: Fri Aug 08, 2008 4:36 pm
by EverLearning
No problem. It happens to everyone. Using IDE which has syntax highlighting and instant error checking helps.
