jw224 Posted May 12, 2010 Share Posted May 12, 2010 Hello I need help in identifying the location that causes the error and on how to fix it. Purpose of this php:http://gaia.ecs.csus.edu/~mei/10/LPA/LPA4/LPA4_B.htm Error Message:"Fatal error: Cannot redeclare displaygreeting() (previously declared in /gaia/class/cs0101/cs010149/html/gt_functions.php:45) in /gaia/class/cs0101/cs010149/html/gt_functions.php on line 45" My Greeting_tree.php file <?php /* Your brief description of this program which may include input, output, requirements, and your design highlights */ # MAIN-PROGRAM include_once("gt_functions.php"); $title = "The Greeting Trees"; html_begin ($title, $title); if ($submit) { if (!$type) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Forgot to select a tree type.</b></font><br>"); } else { //set up the data in a 2-dimensional array to mark the background $A =array(array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0")); //this array A is 11x11, therefore the center of a row is 5 $N = 11; $center = 5; //mark tree leaves for ($i=0; $i < 5; $i++) { for($j= ($center - $i); $j<= ($center + $i); $j++) { $A[$i+2][$j]= "*"; } } //mark tree trunk for ($i = 7; $i < 10; $i++) { $A[$i][$center] = "*"; } //display elements of the array in colors of the tree type for ($i=0; $i< $N; $i++) { for($j=0; $j< $N; $j++) { DisplayChar ($type, $A[$i][$j]); } echo "<BR>"; } DisplayGreeting($type); } } //Form to collect user input: one of the 3 greeting tree types ?> <FORM METHOD="post" ACTION="Greeting_tree.php"><form> <input type="radio" name="type" value="Holiday" /> Holiday <input type="radio" name="type" value="SacState" /> SacState <input type="radio" name="type" value="Surprise"/>Surprise <input type="submit" name="submit" value="Submit" /> </form> <? html_end () ?> My gt_functions.php file <?php # A collection of functions that will be included in Greeting_tree.php function html_begin ($title, $header) { print ("<HTML>\n"); if ($title) print ("<TITLE>$title</TITLE>"); print ("<HEAD>"); Print ("<BODY bgcolor=\"#FFFFFF\">"); if ($header) print ("<H@>$header</H@>"); } function html_end () # put out final HTML tag for page. { print ("</Body></Html>"); } function DisplayChar ($type, $char) //display leave color when $char = "*" and background color when $char = "0" according to given tree type { if ($type == "Holiday") { if ($char == "0") {echo("<font face=\"echo( <face=\ Tahoma\" size=\"5\" color=\"#FF0000\"><b>$char</b></font>");} else {echo("<font face=\"Tahoma\" size=\"5\" color=\"#347C17\"><b>$char</b></font>");}; } else if ($type == "SacState") { if ($char == "0") {echo("<font face=\"echo( <face=\ Tahoma\" size=\"5\" color=\"#EAC117\"><b>$char</b></font>");} else {echo("<font face=\"Tahoma\" size=\"5\" color=\"#347C17\"><b>$char</b></font>");}; } else if ($type == "Surprise") { if ($char == "0") {echo("<font face=\"echo( <face=\ Tahoma\" size=\"5\" color=\"#E41B17\"><b>$char</b></font>");} else {echo("<font face=\"Tahoma\" size=\"5\" color=\"#347C17\"><b>$char</b></font>");}; } function DisplayGreeting ($type) //display greeting message according to given tree type { if ($type == "Holiday") { $message = "Happy Holidays!!!"; } else if ($type == "SacState") { $message = "Go Sac Hornets!!!"; } else if ($type == "Surprise") { $message = "Surprise"; } echo("<font face=\"Tahoma\" size=\"4\" color=\"#E41B17\"><b>$message</b></font><br>");} } ?> Thank you for the assistance. Quote Link to comment https://forums.phpfreaks.com/topic/201547-need-help-identifying-an-error/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2010 Share Posted May 12, 2010 The two pieces of code you posted DON'T produce the error you posted. However, the error does mean that you are including the file where that function definition is at more than once or it is inside of a loop (or perhaps someone configured your server to include the definition prior to your script executing.) It would take seeing all the actual code that resulted in that error to be able to help. Also, since this is not a PHP Installation problem, moving thread to the php help forum section... Quote Link to comment https://forums.phpfreaks.com/topic/201547-need-help-identifying-an-error/#findComment-1057399 Share on other sites More sharing options...
Cagecrawler Posted May 12, 2010 Share Posted May 12, 2010 You're declaring the DisplayGreeting function inside the DisplayChar function so the second time your script calls DsiplayChar() it can't define DisplayGreeting and shows the error. You need to move the last brace (the one closing the DisplayChar function) to above where DisplayGreeting is declared. Quote Link to comment https://forums.phpfreaks.com/topic/201547-need-help-identifying-an-error/#findComment-1057416 Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2010 Share Posted May 12, 2010 Yep, that's correct. jw224, using some real indentation in your code will help, so that you can see exactly what code goes with what. And the reason I did not get that error is because that code (Greeting_tree.php) is way out of date and is dependent on register_globals being on, so when I executed it, the offending code was not actually executed. I would hope that collages that were using php in a classroom would be aware of something that was turned off by default over eight years ago and was a huge security hole when turned on and would not be exposing students to any code that was still dependent on register_globals. Quote Link to comment https://forums.phpfreaks.com/topic/201547-need-help-identifying-an-error/#findComment-1057425 Share on other sites More sharing options...
jw224 Posted May 12, 2010 Author Share Posted May 12, 2010 Alright it works now, thank you both for your assistance. Quote Link to comment https://forums.phpfreaks.com/topic/201547-need-help-identifying-an-error/#findComment-1057456 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.