Question

This code should be written in php. Write a program that allows the user to input...

This code should be written in php.

Write a program that allows the user to input a student's last name, along with that student's grades in English, History, Math, Science, and Geography.

When the user submits this information, store it in an associative array, like this:
Smith=61 67 75 80 72
where the key is the student's last name, and the grades are combined into a single space-delimited string.

Return the user back to the data entry screen, to allow more student names and grades to be entered.

When the user has completed grade entry for all students, allow him/her to generate a grade report. This report should output a table to the screen with a row for each user, and a column for each grade. Failing grades (less than 60) should be printed in red.

Hint: When creating the report, loop through the associative array. Use the split() function to parse the grade string for each student into its own temporary array, that can be looped through to output that student's grades.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Explanation :

The Index File allows the user to enter the Values and gives the values to test.php File. Now, the Grade Report is generated and the Conditions are satisfied here.


Code :

index.html file :

<!DOCTYPE HTML>
<html>
   <body>
       <form action="test.php" method="POST">
           Enter Last Name : <input type="text" name="lname"><br>
           English Marks : <input type="text" name="eng"><br>
           History Marks : <input type="text" name="hist"><br>
           Math Marks : <input type="text" name="math"><br>
           Science Marks : <input type="text" name="sci"><br>
           Geography Marks : <input type="text" name="geo"><br>
           <input type="submit">
       </form>
   </body>
</html>

test.php file :

<!DOCTYPE html>
<html>
   <head>
       <style>
       table {
       font-family: arial, sans-serif;
       border-collapse: collapse;
       width: 100%;
       }

       td, th {
       border: 1px solid #dddddd;
       text-align: left;
       padding: 8px;
       }
       </style>
   </head>
   <body>

       <h1>Grade Report</h1>

       <?php
           function getProperColor($var)
           {
           if ($var < 60)   return '#FF0000';
           else return '#FFFFFF';
           }      
       ?>

       <table>
       <tr>
       <th>Last Name</th>
       <th>English</th>
       <th>History</th>
       <th>Mathematics</th>
       <th>Science</th>
       <th>Geography</th>
       </tr>
       <tr>
       <td><?php echo $_POST["lname"];?></td>
       <td style="background-color: <?php $color = getProperColor($_POST['eng']); echo $color; ?>"> <?php echo $_POST["eng"];?></td>
       <td style="background-color: <?php $color = getProperColor($_POST['hist']); echo $color; ?>"> <?php echo $_POST["hist"];?></td>
       <td style="background-color: <?php $color = getProperColor($_POST['math']); echo $color; ?>"> <?php echo $_POST["math"];?></td>
       <td style="background-color: <?php $color = getProperColor($_POST['sci']); echo $color; ?>"> <?php echo $_POST["sci"];?></td>
       <td style="background-color: <?php $color = getProperColor($_POST['geo']); echo $color; ?>"> <?php echo $_POST["geo"];?></td>
       </tr>
       </table>
   </body>
</html>

Add a comment
Know the answer?
Add Answer to:
This code should be written in php. Write a program that allows the user to input...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT