Jump to content

I am a noob who needs help


isuckat_php

Recommended Posts

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>

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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);
   }
}

Link to comment
Share on other sites

:) 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.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

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.