Question

In: Computer Science

How can I make a PHP web app that will record student's names and grades? Req....

How can I make a PHP web app that will record student's names and grades?

Req.

  • A new table in our database called students.
  • Table should include 2 columns; student_name and student_grade [0 - 100].
  • Need 3 PHP called student_list.php, add_student.php, and delete_student.php.
  • The student_list.php code uses HTML and PHP to list all of the students in your student's table; including their student_name and student_grade [number grade] and letter grade.
  • Convert the number grade to a letter grade as follows.
    • returns 'A' if grade is <= 90
    • returns 'B' if the grade is in the range of 80 through 89
    • returns 'C' if the grade is in the range of 70 through 79
    • returns 'D' if the grade is in the range of 60 through 69
    • returns 'F' if grade is > 60
  • The student_list.php, after the list of students, include a link to Add a Student. This link should display add_student.php.
  • The add_student.php create a form to input the student_name and student_grade [number grade] and a button to add the student [2 textboxes and 1 button].
  • The button in the add_student.php is pressed, insert the new student_name and student_grade [number grade] into the student's table. Then display the student_list.php. The list of students in the student_list.php should show the new student that was just added.
  • In the student_list.php, include a Delete button for each student in the list.
  • The Deletes button is pressed, call the delete_student.php and delete that student from the student's table. Then display the student_list.php. The list of students in the student_list.php should not show the student that was just deleted.

Solutions

Expert Solution

student_list.php

<!DOCTYPE html>
<html>
<head>
<title>Student list</title>
</head>
<body>
<table>
<tr>
   <th>Name</th>
   <th>Number Grade</h>
   <th>Letter Grade</h>
</tr>
   <?php
   $conn = mysql_connect("localhost", "username", "password", "StudentDB");
   if ($conn -> connect_error)
   {
   die("connection failed: ". $conn-> connect_error);  
   }
$sql = "SELECT stname, stgrade from studentab";
   $results = $conn -> query($sql);
  
   if ($result-> num_rows >0)
   {
       while($row = $result-> fetch_assoc()))
       {
           echo "<tr><td>". $row["stname"] ."</td><td>". $row["stgrade"]. "</td>";
           if($row[stgrade] < 60)
           {
           echo "<tr><td>". "F" ."</td>";
           }
           elseif($row[stgrade] >= 60 and $row[stgrade]<=69)
           {
               echo "<tr><td>". "D" ."</td>";
           }
           elseif($row[stgrade] >= 70 and $row[stgrade]<=79)
           {
               echo "<tr><td>". "C" ."</td>";
           }
           elseif($row[stgrade] >= 80 and $row[stgrade]<=89)
           {
               echo "<tr><td>". "B" ."</td>";
           }
           else
           {
               echo "<tr><td>". "A" ."</td>";
           }
       }
       echo "</table>";
    }
   else
   {
       echo("0 Result");
      
   }
$conn-> close();  
?>
</table>
<form action="add_student.php" method="post">
<h2>Form to add student</h2>
<label>Student Name:</label>
<input class="input" name="name" type="text" value="">
<label>Grade:</label>
<input class="input" name="grade" type="text" value="">
<input class="submit" name="submit" type="submit" value="Insert">
</form>

<form action="delete_student.php" method="post">
<h2>Form to delete student</h2>
<label>Student Name:</label>
<input class="input" name="name" type="text" value="">
<input class="submit" name="submit" type="submit" value="Insert">
</form>
</body>
</html>

add_student.php

<?php

$conn = mysql_connect("localhost", "username", "password", "StudentDB");

if ($conn -> connect_error)
   {
   die("connection failed: ". $conn-> connect_error);  
   }

if(isset($_POST['submit']))

{

$name = $_POST['name'];

$grade = $_POST['grade'];

if($name !=' ' || $grade !=' ')

{

$conn -> query("Insert into studenttab(stname, stgrade) values ('$name', '$grade')");

echo "<br/><br/><span>Data Inserted successfully...!!</span>";

echo "<a href=". "student_list.php". ">Display List</a> "

}

else{

echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";

}

}

} $conn-> close();   ?>

delete_student.php

<?php

$conn = mysql_connect("localhost", "username", "password", "StudentDB");

if ($conn -> connect_error)
       {
           die("connection failed: ". $conn-> connect_error);    
       }

if(isset($_POST['submit']))

{

$name = $_POST['name'];


if($name !=' ')

{

$conn -> query("DELETE FROM studenttab where stname= '$name')");

echo "<br/><br/><span>Data Deleted successfully...!!</span>";

echo "<a href=". "student_list.php". ">Display List</a> "   

}

else{

echo "<p>Deletion Failed <br/> Some Fields are Blank....!!</p>";

}

}

} $conn-> close();   ?>


Related Solutions

Create a web page using PHP and HTML that contains a list of movie names available...
Create a web page using PHP and HTML that contains a list of movie names available for rent (at least 10 movies), so that each time you visit the home page, you see a different order of movies in the list. The movie names are required. 2) The rental price for each movie ranges between $1.99 to $7.99. • Create an associative array with a code for the movie as the key (e.g., movie1, movie2, etc.) and the associated rental...
how to read a csv file in php and make a html table? I can't use...
how to read a csv file in php and make a html table? I can't use the PHP function fgetcsv. I can use explode. I can't put a php inside a php. Acme,Walmart,Ross,BJs,Target,Marshalls,Foot Locker,Giant,Charming Charlie 142,160,28,10,5,3,60,0.28,3167 175,180,18,8,4,1,12,0.43,4033 129,132,13,6,3,1,41,0.33,1471 138,140,17,7,3,1,22,0.46,3204 232,240,25,8,4,3,5,2.05,3613 135,140,18,7,4,3,9,0.57,3028 150,160,20,8,4,3,18,4.00,3131 207,225,22,8,4,2,16,2.22,5158 271,285,30,10,5,2,30,0.53,5702 89,90,10,5,3,1,43,0.30,2054 153,157,22,8,3,3,18,0.38,4127 87,90,16,7,3,1,50,0.65,1445 234,238,25,8,4,2,2,1.61,2087 106,116,20,8,4,1,13,0.22,2818 175,180,22,8,4,2,15,2.06,3917 165,170,17,8,4,2,33,0.46,2220 166,170,23,9,4,2,37,0.27,3498 136,140,19,7,3,1,22,0.63,3607 <!DOCTYPE html> <html> <head>    <meta charset="utf-8">    <title>Stores</title>    <link rel="stylesheet" href="style.css"> </head> <body> <h1>Stores</h1> <?php <table> <tr> <th>Acme</th> <th>Walmart</th> <th>Ross</th> <th>BJs</th> <th>Target</th> <th>Marshalls</th> <th>Foot Locker</th>...
Using a diagram explain how PHP makes web pages dynamic
Using a diagram explain how PHP makes web pages dynamic
Using PHP and MYSQL and with a simple customer database, how can I create a simple...
Using PHP and MYSQL and with a simple customer database, how can I create a simple log in and registration system for an ecommerce site
How do I make a simple TCP python web client and web server using only "import...
How do I make a simple TCP python web client and web server using only "import socket"? Basically, the client connects to the server, and sends a HTTP GET request for a specific file (like a text file, HTML page, jpeg, png etc), the server checks for the file and sends a copy of the data to the client along with the response headers (like 404 if not found, or 200 if okay etc). The process would be: You first...
Web Programming: Explain how a session actually works in PHP, including how the client and server...
Web Programming: Explain how a session actually works in PHP, including how the client and server use the session ID to identify the session Then, compare and contrast cookies and sessions as a means of storing state information for a given user. Thank you
Using a combination of HTML/PHP, implement a web page where the users can upload a text...
Using a combination of HTML/PHP, implement a web page where the users can upload a text file, exclusively in .txt format, which contains a string of 400 numbers, such as: 71636269561882670428 85861560789112949495 65727333001053367881 52584907711670556013 53697817977846174064 83972241375657056057 82166370484403199890 96983520312774506326 12540698747158523863 66896648950445244523 05886116467109405077 16427171479924442928 17866458359124566529 24219022671055626321 07198403850962455444 84580156166097919133 62229893423380308135 73167176531330624919 30358907296290491560 70172427121883998797 Your code should contain a PHP function that, accepting the string of 400 numbers in input, is able to find the greatest product of four adjacent numbers in all the...
How would I structure the following PHP (PDO) code into a table format using only PHP?...
How would I structure the following PHP (PDO) code into a table format using only PHP? //Our SQL statement, which will select a list of tables from the current MySQL database. $sql = "SELECT * FROM jobs"; //Prepare our SQL statement, $statement = $pdo->prepare($sql); //Execute the statement. $statement->execute(); //Fetch the rows from our statement. $tables = $statement->fetchAll(PDO::FETCH_NUM); //Loop through our table names. foreach($tables as $table){ //Print the table name out onto the page. echo $table[0], ' '; echo $table[1], '...
I am designing cost comparing/ order app. Can anyone create prototype of this app include that...
I am designing cost comparing/ order app. Can anyone create prototype of this app include that features: cost comparing, offer& coupons, user reviews, order tracking , interactive buttons, design.
how can i make Activity duration estimates?
how can i make Activity duration estimates?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT