I wrote a simple program to calculate the average grades.
But the result does not show up.
Could someone help me check my code?
Thank you!
Turn on error reporting, you have missed a $ (at grades), also you shouldn’t use @, it is at best suppressing errors, which we don’t want to do
I did some changes to the code:
[php]<?php
$gradeField = !empty($_POST[‘grade’]) ? $_POST[‘grade’] : null;
$grades = explode(’ ', $gradeField);
$sum = array_sum($grades);
?>
grade Please enter the grades, use space between two grades: <?php echo 'The average grade is ' . $sum / count($grades); ?> [/php]to add to Jim’s input, don’t do this: [php]$_REQUEST[‘blahblahblah’][/php]
especially as you already know the data is coming via post.
[php][/php]
use $_POST instead like Jim has.
(or $_GET if you are using method="$_GET")
and as for this: @ <<-- :’( :’( :’(
:’( >:( >:(
:o :o ??? :’( :’(
Red