Jump to content

Fatal error: Call to undefined function


CalebVenner

Recommended Posts

Ok, So I get the error

Fatal error: Call to undefined function Main() in C:\PHP Root\Restaurant\OutputOrder.php on line 20

 

Here is my code (I know its horribly messy)

 

<html>
<head>
<link rel="stylesheet" type="text/css" href="style/style.css">
<title>Restaurant</title>
</head>

<body>

<h2> Order Submitted. </h2>

<?php
ini_set('display_errors','1');
error_reporting(E_ALL);
// The code is a little bit messy because for reason I could not call the function GetVars from anywhere in the code
// so I had to post the form retrieval in every function.

														$FolderDate = date("d-m-y");
														// This is where the data from the form is input into variables
														$FolderDate = date("d-m-y");
														$b = date("h:i:s");
														$area = $_POST['area'];
														$name = $_POST['name'];
														$tablenumber = $_POST['tablenumber'];
														$entree = $_POST['fooditem1'];     //retrieving form data
														$notes = $_POST['notes1'];
														$main = $_POST['fooditem2'];
														$desert = $_POST['fooditem3'];
														$servingstaff = $_POST['servingstaff'];
														$time = date("g:i:s A D, F jS Y",$b);
														$time2 = date("h:i a");


if(is_dir("Counters/$FolderDate")) 		// if directory exists
	 {  

FolderCheck();

	} else { 
                                           	  //if it does not exist
mkdir("Counters/$FolderDate");    	 //create the directory
FolderCheck(); 
	}                     		//then run the function counter




function FolderCheck()
{
														$FolderDate = date("d-m-y");
														// This is where the data from the form is input into variables
														$FolderDate = date("d-m-y");
														$b = date("h:i:s");
														$area = $_POST['area'];
														$name = $_POST['name'];
														$tablenumber = $_POST['tablenumber'];
														$entree = $_POST['fooditem1'];     //retrieving form data
														$notes = $_POST['notes1'];
														$main = $_POST['fooditem2'];
														$desert = $_POST['fooditem3'];
														$servingstaff = $_POST['servingstaff'];
														$time = date("g:i:s A D, F jS Y",$b);
														$time2 = date("h:i a");

//this is where the folder is created if it does not exist for the order saving



if(is_dir("orders/$FolderDate"))   // if directory exists
	{		
		CounterText();
	} else  {                                             //if it does not exist
		mkdir("orders/$FolderDate");     //create the directory
		CounterText();                      //then run the function counter

			}



function CounterText()  
{
														$FolderDate = date("d-m-y");
														// This is where the data from the form is input into variables
														$FolderDate = date("d-m-y");
														$b = date("h:i:s");
														$area = $_POST['area'];
														$name = $_POST['name'];
														$tablenumber = $_POST['tablenumber'];
														$entree = $_POST['fooditem1'];     //retrieving form data
														$notes = $_POST['notes1'];
														$main = $_POST['fooditem2'];
														$desert = $_POST['fooditem3'];
														$servingstaff = $_POST['servingstaff'];
														$time = date("g:i:s A D, F jS Y",$b);
														$time2 = date("h:i a");

	clearstatcache();
	if(!file_exists("Counters/$FolderDate/$tablenumber.txt")) //Checks if the file exists "!" means no
					//So a positive return value will mean the file does not exist
	{

	 $fp = fopen("Counters/$FolderDate/$tablenumber.txt","w"); //Create"open" the file
	 fwrite($fp,"0"); //Write a zero into it
	 fclose($fp); //close it

	FolderTableCreate(); //run function outputorder

	} 

	else //otherwise

	{

	FolderTableCreate(); //run function output folder if the file already exists (negative return value)

	}





function FolderTableCreate()
{
														$FolderDate = date("d-m-y");
														// This is where the data from the form is input into variables
														$FolderDate = date("d-m-y");
														$b = date("h:i:s");
														$area = $_POST['area'];
														$name = $_POST['name'];
														$tablenumber = $_POST['tablenumber'];
														$entree = $_POST['fooditem1'];     //retrieving form data
														$notes = $_POST['notes1'];
														$main = $_POST['fooditem2'];
														$desert = $_POST['fooditem3'];
														$servingstaff = $_POST['servingstaff'];
														$time = date("g:i:s A D, F jS Y",$b);
														$time2 = date("h:i a");


//This is where a folder is created to store the days orders,
						// if it is not already created it is made using a simple if statement.

if(is_dir("orders/$FolderDate/$tablenumber")) 
	{ 		 			// if directory exists

OutputOrder();

} else {                                              //if it does not exist
mkdir("orders/$FolderDate/$tablenumber");    			 //create the directory

OutputOrder(); }                    			//then run the function counter




function OutputOrder()   //started another function within the first, only way this would work

	{
														$FolderDate = date("d-m-y");
														// This is where the data from the form is input into variables
														$FolderDate = date("d-m-y");
														$b = date("h:i:s");
														$area = $_POST['area'];
														$name = $_POST['name'];
														$tablenumber = $_POST['tablenumber'];
														$entree = $_POST['fooditem1'];     //retrieving form data
														$notes = $_POST['notes1'];
														$main = $_POST['fooditem2'];
														$desert = $_POST['fooditem3'];
														$servingstaff = $_POST['servingstaff'];
														$time = date("g:i:s A D, F jS Y",$b);
														$time2 = date("h:i a");



		// This is the counter
		$File = "Counters/$FOlderDate/$tablenumber.txt"; //opens file, reads value, stores it in a variable
		$handle = fopen($File, 'r+') ;
		$data = fread($handle, 512) ;
		$count = $data + 1; //increments it by one
		fseek($handle, 0) ;  //returns "pointer" to zero so that it overwrites old number.
		fwrite($handle, $count) ; //writes it back into the file, 	
		fclose($handle) ;




		// This is where the variables are output to the textfile
		$file=fopen("orders/$FolderDate/$tablenumber/Order$count.txt", "w");
		fputs($file, "Patron's Name: $name\n");
		fputs($file, "Room: $area\n");
		fputs($file, "Table Number: $tablenumber\n");
		fputs($file, "Time: $time2\n");
		fputs($file, "Meal 1: $entree\n");            //writing form data
		fputs($file, "Meal 2: $main\n");
		fputs($file, "Meal 3: $desert\n");
		fputs($file, "Extra Notes: $notes\n");
		fputs($file, "Server: $servingstaff\n");
		fputs($file, "Date: $time\n");

		fclose($file);		
}
}
}
}
?>

<h2><a href="/Restaurant/index.php">Return to Main Page</a><h2> 
</body>
</html>

 

Just ignore the random variables that are tabbed to the right. (Unless they are the problem)

 

I am happy to answer any questions, another problem that I have is that I find I cannot call a function from within another function, so I have to place them entirely within one another.

 

Thankyou for any help in advance.

Link to comment
Share on other sites

No function called Main is called in the code that you've posted. This is your OutputOrder.php  script, right?

 

another problem that I have is that I find I cannot call a function from within another function, so I have to place them entirely within one another.
Why not, what does it do if you try?

 

Link to comment
Share on other sites

Sorry, posted the wrong error, foolish of me  :-[

 

Notice: A non well formed numeric value encountered in C:\PHP Root\Restaurant\OutputOrder.php on line 29

 

Notice: A non well formed numeric value encountered in C:\PHP Root\Restaurant\OutputOrder.php on line 61

 

Fatal error: Call to undefined function CounterText() in C:\PHP Root\Restaurant\OutputOrder.php on line 73

Link to comment
Share on other sites

No function called Main is called in the code that you've posted. This is your OutputOrder.php  script, right?

 

another problem that I have is that I find I cannot call a function from within another function, so I have to place them entirely within one another.
Why not, what does it do if you try?

 

It simply loads the page as blank

Link to comment
Share on other sites

another problem that I have is that I find I cannot call a function from within another function, so I have to place them entirely within one another.

 

I think you mean, that the variables aren't available inside the functions, right? You should read up on variable scope. Redefining the same variables over and over again is not the way to do it.

 

Edit:

 

Notice: A non well formed numeric value encountered in C:\PHP Root\Restaurant\OutputOrder.php on line 29

 

Notice: A non well formed numeric value encountered in C:\PHP Root\Restaurant\OutputOrder.php on line 61

 

Fatal error: Call to undefined function CounterText() in C:\PHP Root\Restaurant\OutputOrder.php on line 73

 

First two errors occur because the second parameter to date(), $b, should be an integer (Unix timestamp). Solve it by simply removing the second parameter, as it seems you want to use the current timestamp.

 

Looking at the third error, I realize how much a mess the code is. It seems you're defining functions within function definitions?

Link to comment
Share on other sites

another problem that I have is that I find I cannot call a function from within another function, so I have to place them entirely within one another.

 

I think you mean, that the variables aren't available inside the functions, right? You should read up on variable scope. Redefining the same variables over and over again is not the way to do it.

 

Thanks, as you can tell I'm a tad new to all of this. Appreciate the help.

Link to comment
Share on other sites

The errors you are getting is because the date function is expecting an int, which would be a time stamp ie. via mktim, where as you'er passing it a string.

 

However doing this on the CURRENT time seems pointless and you may as well just use date("g:i:s A D, F jS Y");

and because your not including a date ($b just container hours mins and seconds) it will output a date in 1970.

Link to comment
Share on other sites

ok with the date function you can give it a timestamp, which will give you a formated date for the given stamp ie

 

 

$timestamp = mktime(0, 0, 0, 12, 25, 1997)

 

will give you a time stamp for the 25th of december 1997, you can then use this with the date function to say, output what day the 25th of that month was

 

date('l', $timestamp);

 

To get rid of that error you can simply remove the $b. What is it your trying to make time equal?, if its just the current date in the format specified by the letters then there is no need to pass it a time stamp.

 

Link to comment
Share on other sites

Is this better?

Declared all of my variables at the start, all functions are seperate and I got rid of $b

 

 

 

<html>
<head>
<link rel="stylesheet" type="text/css" href="style/style.css">
<title>Restaurant</title>
</head>

<body>

<h2> Order Submitted. </h2>

<?php
ini_set('display_errors','1');
error_reporting(E_ALL);

$FolderDate = date("d-m-y");															// This is where the data from the form is input into variables
$FolderDate = date("d-m-y");
$area = $_POST['area'];
$name = $_POST['name'];
$tablenumber = $_POST['tablenumber'];
$entree = $_POST['fooditem1'];     //retrieving form data
$notes = $_POST['notes1'];
$main = $_POST['fooditem2'];
$desert = $_POST['fooditem3'];
$servingstaff = $_POST['servingstaff'];
$time = date("g:i:s A D, F jS Y");
$time2 = date("h:i a");


if(is_dir("Counters/$FolderDate")) 		// if directory exists
	 {  

FolderCheck();

	} else { 
                                           	  //if it does not exist
mkdir("Counters/$FolderDate");    	 //create the directory
FolderCheck(); 
	}                     		//then run the function counter




function FolderCheck()
{

if(is_dir("orders/$FolderDate"))   // if directory exists
	{		
		CounterText();
	} else  {                                             //if it does not exist
		mkdir("orders/$FolderDate");     //create the directory
		CounterText();                      //then run the function counter

			}


}
function CounterText()  
{


clearstatcache();
	if(!file_exists("Counters/$FolderDate/$tablenumber.txt")) //Checks if the file exists "!" means no
					//So a positive return value will mean the file does not exist
	{

	 $fp = fopen("Counters/$FolderDate/$tablenumber.txt","w"); //Create"open" the file
	 fwrite($fp,"0"); //Write a zero into it
	 fclose($fp); //close it

	FolderTableCreate(); //run function outputorder

	} 

	else //otherwise

	{

	FolderTableCreate(); //run function output folder if the file already exists (negative return value)

	}


}


function FolderTableCreate()
{


if(is_dir("orders/$FolderDate/$tablenumber")) 
	{ 		 			// if directory exists

OutputOrder();

} else {                                              //if it does not exist
mkdir("orders/$FolderDate/$tablenumber");    			 //create the directory

OutputOrder(); }                    			//then run the function counter




function OutputOrder()
{


// This is the counter
		$File = "Counters/$FOlderDate/$tablenumber.txt"; //opens file, reads value, stores it in a variable
		$handle = fopen($File, 'r+') ;
		$data = fread($handle, 512) ;
		$count = $data + 1; //increments it by one
		fseek($handle, 0) ;  //returns "pointer" to zero so that it overwrites old number.
		fwrite($handle, $count) ; //writes it back into the file, 	
		fclose($handle) ;




		// This is where the variables are output to the textfile
		$file=fopen("orders/$FolderDate/$tablenumber/Order$count.txt", "w");
		fputs($file, "Patron's Name: $name\n");
		fputs($file, "Room: $area\n");
		fputs($file, "Table Number: $tablenumber\n");
		fputs($file, "Time: $time2\n");
		fputs($file, "Meal 1: $entree\n");            //writing form data
		fputs($file, "Meal 2: $main\n");
		fputs($file, "Meal 3: $desert\n");
		fputs($file, "Extra Notes: $notes\n");
		fputs($file, "Server: $servingstaff\n");
		fputs($file, "Date: $time\n");

		fclose($file);

	}

?>

<h2><a href="/Restaurant/index.php">Return to Main Page</a><h2> 
</body>
</html>

 

The time does not matter too much, it was just there as a point of reference for my theoretical restaurant manager to refer to.

 

 

EDIT: Declare my functions BEFORE calling them?

Link to comment
Share on other sites

Declare my functions BEFORE calling them?

 

That's good practice if you ask me. If I remember correctly, PHP 4 required it. But PHP 5 doesn't.

 

You forgot to end the definition of FolderTableCreate(). And you still need to fix your scope problem, 'cause the variables won't be available inside the functions the way you have it now. Look at functions as something that takes input, manipulates it, and returns output dependent on the given input. Your functions don't take any input.

Link to comment
Share on other sites

OK, its working 100% as intented, thanks heaps guys.

 

I ended up just redeclaring the varialbes and retrieving them from the form in each function because I was sick of it, I will learn it tomorrow, I'm tired.

 

Again, thanks, appreciate the help.

 

Goodnight.

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.