5 Replies - 625 Views - Last Post: 13 May 2013 - 08:15 AM Rate Topic: -----

#1 Joker302w  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-May 13

I need help linking my php to my html

Posted 13 May 2013 - 06:50 AM

So i'm confused How would you like your php to your html page?
so Here is my code for a grade calc but do i dont know how to link it... i feel stupid:/
<html>
<head>
<link rel="stylesheet" type="text/css" href="gradecalc.css" />
<title>Grade Calculator</title>
</head>
<body>
<?php
$grade=0;
if ($_POST['Quiz1'] >= 0 && $_POST['Quiz1'] <= 100)
	$grade = $grade + $_POST['Quiz1'] * 0.05;
else
  	$grade = $grade + 5; 
if ($_POST['Mid-Term'] >= 0 && ($_POST['Mid-Term'] <= 100))
	$grade = $grade + $_POST['Mid-Term'] * 0.30;
else
  	$grade = $grade + 30; 
if ($_POST['Quiz2'] >= 0 && ($_POST['Quiz2'] <= 100))
	$grade = $grade + $_POST['Quiz2'] * 0.05;
else
  	$grade = $grade + 5; 
if ($_POST['AL1'] >= 0 && ($_POST['AL1'] <= 100))
	$grade = $grade + $_POST['AL1'] * 0.05;
else
   	$grade = $grade + 5; 
if ($_POST['AL2'] >= 0 && ($_POST['AL2'] <= 100))
	$grade = $grade + $_POST['AL2'] * 0.05;
else
  	$grade = $grade + 5; 
if ($_POST['Participation'] >= 0 && ($_POST['Participation'] <= 100))
	$grade = $grade + $_POST['Participation'] * 0.10;
else
 	$grade = $grade + 10; 
if ($_POST['Final'] >= 0 && ($_POST['Final'] <= 100))
	$grade = $grade + $_POST['Final'] * 0.40;
else
  	$grade = $grade + 40;

?>
<?php
echo "Grade Report: <br />";
echo "<br />";
?>
Your final grade percentage will be:  <?php echo $grade . "%";
echo "<br />";
{
if ($grade > 90.9)
	echo "Your final grade for the course will be: A+ <br />";
elseif ($grade > 85.9)
	echo "Your final grade for the course will be: A  <br />";
elseif ($grade > 79)
	echo "Your final grade for the course will be: A-  <br />";
elseif ($grade > 76.9)
	echo "Your final grade for the course will be: B+  <br />";
elseif ($grade >71.9)
	echo "Your final grade for the course will be: B  <br />";
elseif ($grade > 69.9)
	echo "Your final grade for the course will be: B-  <br />";
elseif ($grade > 65.9)
	echo "Your final grade for the course will be: C+  <br />";
elseif ($grade > 59.9)
	echo "Your final grade for the course will be: C  <br />";
elseif ($grade > 54.9)
	echo "Your final grade for the course will be: C-  <br />";
elseif ($grade > 49.9)
	echo "Your final grade for the course will be: P  <br />";
else
	echo "Your final grade for the course will be: F  <br />";

}

?>
</body>
</html>






Is This A Good Question/Topic? 0
  • +

Replies To: I need help linking my php to my html

#2 Joker302w  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-May 13

Re: I need help linking my php to my html

Posted 13 May 2013 - 06:58 AM

So Ive been writing this php and i forgot how to link it to my html Any help?
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3572
  • View blog
  • Posts: 10,414
  • Joined: 08-June 10

Re: I need help linking my php to my html

Posted 13 May 2013 - 07:05 AM

What do you mean by "link PHP to HTML" ?

both languages are not linked, PHP has to output HTML.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9498
  • View blog
  • Posts: 35,845
  • Joined: 12-June 08

Re: I need help linking my php to my html

Posted 13 May 2013 - 07:11 AM

How about you not tack that post onto a topic from Feb. 2010? Cut the post, and merged it with your other vaguely worded thread.
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,612
  • Joined: 23-August 08

Re: I need help linking my php to my html

Posted 13 May 2013 - 07:41 AM

if ($_POST['Quiz1'] >= 0 && $_POST['Quiz1'] <= 100)
	$grade = $grade + $_POST['Quiz1'] * 0.05;
else
  	$grade = $grade + 5; 
if ($_POST['Mid-Term'] >= 0 && ($_POST['Mid-Term'] <= 100))
	$grade = $grade + $_POST['Mid-Term'] * 0.30;
else
  	$grade = $grade + 30; 
if ($_POST['Quiz2'] >= 0 && ($_POST['Quiz2'] <= 100))
	$grade = $grade + $_POST['Quiz2'] * 0.05;
else
  	$grade = $grade + 5; 
if ($_POST['AL1'] >= 0 && ($_POST['AL1'] <= 100))
	$grade = $grade + $_POST['AL1'] * 0.05;
else
   	$grade = $grade + 5; 
if ($_POST['AL2'] >= 0 && ($_POST['AL2'] <= 100))
	$grade = $grade + $_POST['AL2'] * 0.05;
else
  	$grade = $grade + 5; 
if ($_POST['Participation'] >= 0 && ($_POST['Participation'] <= 100))
	$grade = $grade + $_POST['Participation'] * 0.10;
else
 	$grade = $grade + 10; 
if ($_POST['Final'] >= 0 && ($_POST['Final'] <= 100))
	$grade = $grade + $_POST['Final'] * 0.40;
else
  	$grade = $grade + 40;

?>

All of these $_POST variables need to be coming from input elements with those names in an HTML form which uses the method="POST" and an action equal to the filename of this HTML/PHP file you've provided.

http://php.net/manua...orial.forms.php
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3572
  • View blog
  • Posts: 10,414
  • Joined: 08-June 10

Re: I need help linking my php to my html

Posted 13 May 2013 - 08:15 AM

View PostJoker302w, on 13 May 2013 - 03:50 PM, said:

if ($_POST['Quiz1'] >= 0 && $_POST['Quiz1'] <= 100)
	$grade = $grade + $_POST['Quiz1'] * 0.05;
else
  	$grade = $grade + 5; 
if ($_POST['Mid-Term'] >= 0 && ($_POST['Mid-Term'] <= 100))
	$grade = $grade + $_POST['Mid-Term'] * 0.30;
else
  	$grade = $grade + 30; 
// ...


a lot of these can be simplified by filter functions if the submitted values are supposed to be integers:
$limits = array('options' => array('min_range' => 0, 'max_range' => 100));
$quiz = filter_input(INPUT_POST, 'Quiz1', FILTER_VALIDATE_INT, $limits);
$grade += is_int($quiz) ? $quiz/20 : 5;

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1