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...
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 print the sales reports grouped by the room grades using the java code...
How can I print the sales reports grouped by the room grades using the java code below: ----------------------------------------------------------------------------------------------------------------------------------- public class Book {    String bookno;    int ff;    Customer cust;       public String getBookingNumber()    {        return bookno;    }       public void BookNew(Customer c,Standard stand,Deluxe dx,Suite suite,int iStandard,int flag1,int iDelux,int flag2,int isdx,int flag3)       {        cust=c;    Fare f=new Fare();    int no,i;          if(c.type==1)    {       ...
How can I get res_ticket using php getstring? var post_data = "res_id=RYSEZ21786" + "&res_ticket=res8azjcfLQTHNU2mVtG" + "&pan="...
How can I get res_ticket using php getstring? var post_data = "res_id=RYSEZ21786" + "&res_ticket=res8azjcfLQTHNU2mVtG" + "&pan=" + encodeURIComponent(document.getElementById('pan').value) + "&pan_mm=" + encodeURIComponent(document.getElementById('exp_month').value) + "&pan_yy=" + encodeURIComponent(document.getElementById('exp_year').value) + "&cardholder=" + encodeURIComponent(document.getElementById('cardholder').value) + avs_details + cvd_details + "&doTransaction=res_add";
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT