isuckat_php Posted March 29, 2010 Share Posted March 29, 2010 I dont know how to fix this! assistance would be greatly appreciated.: everytime i try to load my page i get: Parse error: parse error, unexpected '{' in /gaia/class/cs0101/cs010129/html/freegumph.php on line 13 this is my code: <html> <body> <?php if ($submit) { if (($score_1 == "") || ($score_2 =="") || ($score_3 =="") || (!$calc)) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Oops, you forgot to supply some information. Please correct the problem below.</b></font><br>"); } elseif ((!ereg("[0-9]",$score_1) || (!ereg("[0-9]",$score_2) || (!ereg("[0-9]",$score_3)) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Please restrict your input to only numbers.</b></font><br>"); } } else { $avg=($score_1 + $score_2 + score_3)/3 if ($avg >= 29) { echo $total = 0 } else { echo $total= ((29 - $avg) * (7/10)) } print("The freegumpher handicap is:". $total); } } ?> <form method="post" action="freegumph.php"> Enter your three most <i>recent</i> Freegumpher scores to calculate Handicap:<br/> <br/> <input type="text" name="score_1" size=8 <input type="text" name="score_2" size=8 <input type="text" name="score_3" size=8 /><br /><br/> <input type="submit" name="submit" value="Calculate Handicap"/> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/196913-i-am-a-noob-who-needs-help/ Share on other sites More sharing options...
hcdarkmage Posted March 29, 2010 Share Posted March 29, 2010 Your missing some end )'s : elseif ((!ereg("[0-9]",$score_1)) || (!ereg("[0-9]",$score_2)) || (!ereg("[0-9]",$score_3))) Don't forget to clean up your echo statements after that by putting the semicolon after each one: $avg=($score_1 + $score_2 + score_3)/3; if ($avg >= 29) { echo $total = 0; } else { echo $total= ((29 - $avg) * (7/10)); } print("The freegumpher handicap is:". $total); Quote Link to comment https://forums.phpfreaks.com/topic/196913-i-am-a-noob-who-needs-help/#findComment-1033795 Share on other sites More sharing options...
jcbones Posted March 29, 2010 Share Posted March 29, 2010 Cleaned up all parse errors. <html> <body> <?php if ($submit) { if (($score_1 == "") || ($score_2 =="") || ($score_3 =="") || (!$calc)) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Oops, you forgot to supply some information. Please correct the problem below.</b></font><br>"); } elseif ((!ereg("[0-9]",$score_1)) || (!ereg("[0-9]",$score_2) || (!ereg("[0-9]",$score_3)))) //missing 4 )'s in this statement. { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Please restrict your input to only numbers.</b></font><br>"); } } else { $avg=($score_1 + $score_2 + score_3)/3; //missed semi-colon; if ($avg >= 29) { echo $total = 0; //missed semi-colon; } else { $total = ((29 - $avg) * (7/10)); //didn't need the echo here, just the variable. } print("The freegumpher handicap is:". $total); //removed bracket } from here. } ?> <form method="post" action="freegumph.php"> Enter your three most <i>recent</i> Freegumpher scores to calculate Handicap:<br/> <br/> <input type="text" name="score_1" size=8 <input type="text" name="score_2" size=8 <input type="text" name="score_3" size=8 /><br /><br/> <input type="submit" name="submit" value="Calculate Handicap"/> </form> </body> </html> Now, the function ereg is depreciated, and will no longer be supported in php6. You will be fine, as long as you don't update to that version. Quote Link to comment https://forums.phpfreaks.com/topic/196913-i-am-a-noob-who-needs-help/#findComment-1033799 Share on other sites More sharing options...
isuckat_php Posted March 29, 2010 Author Share Posted March 29, 2010 thank you kind sir, i hope you a really great day! Quote Link to comment https://forums.phpfreaks.com/topic/196913-i-am-a-noob-who-needs-help/#findComment-1033800 Share on other sites More sharing options...
isuckat_php Posted March 29, 2010 Author Share Posted March 29, 2010 I am running into a few problems. 1) It calculates: The freegumpher handicap is:20.3 The problem with this is that i dont want it to output anything until the user gives numbers. i dont know where it came up with his number 2) Everytime I input a number it outputs: Oops, you forgot to supply some information. Please correct the problem below. The problem with this is that i dont want that message to show up unless one of the boxes is not filled. this is the webpage: http://athena.ecs.csus.edu/~cs010129/freegumph.php this is the adjusted code: <html> <body> <?php if ($submit) { if (($score_1 == "") || ($score_2 =="") || ($score_3 =="") || (!$calc)) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Oops, you forgot to supply some information. Please correct the problem below.</b></font><br>"); } elseif ((!ereg("[0-9]",$score_1)) || (!ereg("[0-9]",$score_2) || (!ereg("[0-9]",$score_3)))) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Please restrict your input to only numbers.</b></font><br>"); } } else { $avg=($score_1 + $score_2 + score_3)/3; if ($avg >= 29) { echo $total = 0; } else { $total = ((29 - $avg) * (7/10)); } print("The freegumpher handicap is:". $total); } ?> <form method="post" action="freegumph.php"> Enter your three most <i>recent</i> Freegumpher scores to calculate Handicap:<br/> <br/> <input type="text" name="score_1" size=8 <input type="text" name="score_2" size=8 <input type="text" name="score_3" size=8 /><br /><br/> <input type="submit" name="submit" value="Calculate Handicap"/> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/196913-i-am-a-noob-who-needs-help/#findComment-1033802 Share on other sites More sharing options...
hcdarkmage Posted March 29, 2010 Share Posted March 29, 2010 Remove your else statement. Your basically telling your page that if there is something submitted, run the error coding and any other time run the calculations. if ($submit) { $goodtogo = true; if (($score_1 == "") || ($score_2 =="") || ($score_3 =="") || (!$calc)) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Oops, you forgot to supply some information. Please correct the problem below.</b></font><br>"); $goodtogo = false; } elseif ((!ereg("[0-9]",$score_1)) || (!ereg("[0-9]",$score_2) || (!ereg("[0-9]",$score_3)))) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Please restrict your input to only numbers.</b></font><br>"); $goodtogo = false; } if ($goodtogo == true){ $avg=($score_1 + $score_2 + score_3)/3; if ($avg >= 29) { echo $total = 0; } else { $total = ((29 - $avg) * (7/10)); } print("The freegumpher handicap is:". $total); } } Quote Link to comment https://forums.phpfreaks.com/topic/196913-i-am-a-noob-who-needs-help/#findComment-1033811 Share on other sites More sharing options...
isuckat_php Posted March 29, 2010 Author Share Posted March 29, 2010 That got rid of the output displaying automatically but, it still keeps saying no matter what numbers I put into the text: Oops, you forgot to supply some information. Please correct the problem below. My code is set to tell it to only display that if only one of my input text are left blank. Quote Link to comment https://forums.phpfreaks.com/topic/196913-i-am-a-noob-who-needs-help/#findComment-1033817 Share on other sites More sharing options...
hcdarkmage Posted March 29, 2010 Share Posted March 29, 2010 Try this: if ($submit != ""){ $goodtogo = true; if (($score_1 == "") || ($score_2 =="") || ($score_3 =="") || (!$calc)){ echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Oops, you forgot to supply some information. Please correct the problem below.</b></font><br>"); $goodtogo = false; } elseif ((!ereg("[0-9]",$score_1)) || (!ereg("[0-9]",$score_2) || (!ereg("[0-9]",$score_3)))){ echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Please restrict your input to only numbers.</b></font><br>"); $goodtogo = false; } if ($goodtogo == true){ $avg=($score_1 + $score_2 + score_3)/3; if ($avg >= 29){ echo $total = 0; }else{ $total = ((29 - $avg) * (7/10)); } print("The freegumpher handicap is:". $total); } } I am not able to test this, but it should work. It checks to see if $submit has a value. Quote Link to comment https://forums.phpfreaks.com/topic/196913-i-am-a-noob-who-needs-help/#findComment-1033821 Share on other sites More sharing options...
isuckat_php Posted March 29, 2010 Author Share Posted March 29, 2010 http://athena.ecs.csus.edu/~cs010129/freegumph.php i implemented the code you gave me. Do i need to delete the if (($score_1 == "") || ($score_2 =="") || ($score_3 =="") || (!$calc)) because i have: if ($submit != "") Quote Link to comment https://forums.phpfreaks.com/topic/196913-i-am-a-noob-who-needs-help/#findComment-1033825 Share on other sites More sharing options...
hcdarkmage Posted March 29, 2010 Share Posted March 29, 2010 No. Because you still need to see if those have empty values. What I gave you is just to see if the form was submitted. That's all. Then it checks to makes sure that there are scores. Quote Link to comment https://forums.phpfreaks.com/topic/196913-i-am-a-noob-who-needs-help/#findComment-1033826 Share on other sites More sharing options...
jcbones Posted March 29, 2010 Share Posted March 29, 2010 I first thought maybe your server had globals turned off, so the variables were always empty. Then I saw what all of us missed. (!calc) is not defined or set, so it will always validate to false. I went ahead, and defined the variables also, and since I did that, I'll go ahead and give it to you also. <html> <body> <?php if (isset($_POST['submit'])) { $score_1 = (isset($_POST['score_1'])) ? $_POST['score_1'] : ''; $score_2 = (isset($_POST['score_2'])) ? $_POST['score_2'] : ''; $score_3 = (isset($_POST['score_3'])) ? $_POST['score_3'] : ''; if (($score_1 == "") || ($score_2 =="") || ($score_3 =="")) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Oops, you forgot to supply some information. Please correct the problem below.</b></font><br>"); } elseif ((!ereg("[0-9]",$score_1)) || (!ereg("[0-9]",$score_2) || (!ereg("[0-9]",$score_3)))) //missing 4 )'s in this statement. { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Please restrict your input to only numbers.</b></font><br>"); } else { $avg=($score_1 + $score_2 + $score_3)/3; //missed semi-colon; if ($avg >= 29) { echo $total = 0; //missed semi-colon; } else { $total = ((29 - $avg) * (7/10)); //didn't need the echo here, just the variable. } print("The freegumpher handicap is:". $total); //removed bracket } from here. } } ?> <form method="post" action=""> Enter your three most <i>recent</i> Freegumpher scores to calculate Handicap:<br/> <br/> <input type="text" name="score_1" size=8 <input type="text" name="score_2" size=8 <input type="text" name="score_3" size=8 /><br /><br/> <input type="submit" name="submit" value="Calculate Handicap"/> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/196913-i-am-a-noob-who-needs-help/#findComment-1033828 Share on other sites More sharing options...
isuckat_php Posted March 29, 2010 Author Share Posted March 29, 2010 works wonderfully! hope hcdarkmage and jcbones have an awesome day because you guys just made my day! now to study how the code works... Quote Link to comment https://forums.phpfreaks.com/topic/196913-i-am-a-noob-who-needs-help/#findComment-1033832 Share on other sites More sharing options...
juliaadams Posted March 30, 2010 Share Posted March 30, 2010 Fixed with the same issue. Wandering for help from couple of days. After visit this forum i found the solution of my problem. I fixed this assistance. It really works thanks. Quote Link to comment https://forums.phpfreaks.com/topic/196913-i-am-a-noob-who-needs-help/#findComment-1033998 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.