Guest User

Untitled

a guest
Oct 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. <?php
  2.  
  3. $connection = mysqli_connect ('localhost', 'user', 'password', 'testdb');
  4.  
  5. if (!$connection){
  6. echo 'Not connected to server';
  7. }
  8.  
  9. $select_db = mysqli_select_db($connection, 'testdb');
  10.  
  11. if (!$select_db){
  12. echo 'Not connected to database';
  13. }
  14.  
  15. $sql= "SELECT * FROM students";
  16.  
  17. $query = mysqli_query($connection, $sql);
  18.  
  19. if (!$query) {
  20. die ('SQL Error: ' . mysqli_error($connection));
  21. }
  22.  
  23. if(isset($_POST['update'])){
  24. $UpdateQuery = "UPDATE `students` SET `elected_subject`='$ElectedSubject'";
  25. mysql_query($UpdateQuery, $con);
  26. };
  27. ?>
  28.  
  29.  
  30. <h1><strong>Student Record</strong></h1>
  31. <table id = "result" class="data-table">
  32. <caption class="title"></caption>
  33. <thead>
  34. <tr>
  35.  
  36. <th>Student ID</th>
  37. <th>Student Name</th>
  38. <th>Father Name</th>
  39. <th>Class</th>
  40. <th>Selected Subject</th>
  41. <th>View/Update</th>
  42.  
  43.  
  44. </tr>
  45. </thead>
  46. <tbody>
  47. <?php
  48. $no = 1;
  49. $total = 0;
  50. while ($row = mysqli_fetch_array($query))
  51. {
  52. echo "<form action=update_students.php method=post>";
  53. $student = $row['stu_id'] == 0 ? '' : number_format($row['stu_id']);
  54. echo '<tr>
  55.  
  56. <td>'.$row['student_id'].'</td>
  57. <td>'.$row['student_name'].'</td>
  58. <td>'.$row['father_name'].'</td>
  59. <td>'.$row['class'].'</td>
  60. <td>'.$row['elected_subject'].'</td>
  61. <td>' . "<input type='submit' name='update' value='update'>" . '</td>
  62.  
  63. </tr>';
  64. $total += $row['stu_id'];
  65. $no++;
  66. }?>
  67. </tbody>
  68.  
  69. </table>
Add Comment
Please, Sign In to add comment