Jump to content

I am running into a few problems.


isuckat_php

Recommended Posts

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 after calculation button is clicked.

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>

 

Help is greatly appreciated.  :)

Link to comment
Share on other sites

To test wether a form or variable was submitted it is good practice to test with the following method:

<?PHP
if (isset($_GET['submit'])) {
	if (isset($_GET['score_1']) && $_GET['score_1'] != '' && 
			isset($_GET['score_2']) && $_GET['score_2'] != '' && 
			isset($_GET['score_3']) && $_GET['score_3'] != '') {
		if (do other checks ie. is_numeric... regexpr...) {
			//error
			echo "<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Please restrict your input to only numbers.</b></font><br>";
		} else {
			//good to continue
			$avg=($_GET['score_1'] + $_GET['score_2'] + $_GET['score_3'])/3;
			if ($avg >= 29)				{
				$total = 0;
			else
				$total = ((29 - $avg) * (7/10));   
			print("The freegumpher handicap is:". $total);   
		}
	} else {
		//error
		echo "<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Oops, you forgot to supply some information.  Please correct the problem below.</b></font><br>";
	}
}
?>

 

Link to comment
Share on other sites

<html>
<body>

<?php
if($HTTP_SERVER_VARS['REQUEST_METHOD']=='POST'){
$submit=$_POST["submit"];
$score_1=$_POST["score_1"];
$score_2=$_POST["score_2"];
$score_3=$_POST["score_3"];
if ($submit)
{
  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)))) 
   {
    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

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.