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
https://forums.phpfreaks.com/topic/196915-i-am-running-into-a-few-problems/
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>";
	}
}
?>

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.