2 Replies - 396 Views - Last Post: 04 October 2012 - 11:08 PM Rate Topic: -----

#1 rhallig  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-October 12

How can I write this code?

Posted 04 October 2012 - 04:51 PM

I am trying to do my homework, but I am not getting the output that I need from the input I am putting in my PHP file. My HTML interface seems to be working fine, but the output comes out blank. My assignment is to be able to write a program that will be able to have an imminent amount of grades entered, and it will be averaged together after the user clicks the submit button. I have tried to research the explode function so that the user can enter different values with exploding the comma symbol, but I am confused on how to be able to find the average of all of those values.

Here is my code for PHP that I have so far

<?php 

$a=count(func_num_args());
$arg=func_get_args();
$Mean_grade=(array_sum($arg))/$a;

$post=$_POST['Mean_grade'];
$explode=explode(",",$post);


echo "<h1>"."Your average of all grades is " . $Mean_grade . "</h1>";
?>


Here is the code for my HTML interface page:
<html>
<head>
<title>Was your test average the meanest?</title>
</head>
<body>
<h1>Is your average mean?</h1>
<form ACTION="PHPfile.php" Method="Post">
<input type="text" name="Mean_grade"></input>
<br><input type="submit" value="SUBMIT"></input>
</form>
</body>






</html>


Am I on the right track/what do I need to do to get the right output?

This post has been edited by Dormilich: 04 October 2012 - 10:54 PM


Is This A Good Question/Topic? 0
  • +

Replies To: How can I write this code?

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,740
  • Joined: 08-August 08

Re: How can I write this code?

Posted 04 October 2012 - 05:25 PM

What are func_num_args() and func_get_args()? (In other words: what do you think they're going to do where you use them?)

Why do this:
$x = $_POST['x'];
$y = explode(",",$x);

when you could just do this?
$y = explode(",",$_POST['x'];

This post has been edited by CTphpnwb: 04 October 2012 - 05:38 PM

Was This Post Helpful? 1
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3392
  • View blog
  • Posts: 9,589
  • Joined: 08-June 10

Re: How can I write this code?

Posted 04 October 2012 - 11:08 PM

some comments to the HTML.

in HTML <input> is an empty element. the closing tags are only valid in XHTML, which you serve as XHTML (MIME Type application/xhtml+xml, file extension .xhtml).

from the GUI point-of-view, providing a field for every grade would make more sense, but you’d need Javascript to do that.

you’re missing a DTD

the HTML output of the processing PHP file (at least as given) lacks the structure of an HTML document (DTD, head, body, etc.)

use a consistent HTML casing (per definition, HTML uses upper-case tag names and lower-case attribute names, but tags are usually written lower-case, too. in contrast, XHTML uses all lower-case tag names and attribute names (everything else causes an error))


and something funny: "Is your average mean?" can mean a lot of things (average, poor, nasty (to list only the most common ones)), not sure if the pun was intended.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1