Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $connection = mysqli_connect ('localhost', 'user', 'password', 'testdb');
- if (!$connection){
- echo 'Not connected to server';
- }
- $select_db = mysqli_select_db($connection, 'testdb');
- if (!$select_db){
- echo 'Not connected to database';
- }
- $sql= "SELECT * FROM students";
- $query = mysqli_query($connection, $sql);
- if (!$query) {
- die ('SQL Error: ' . mysqli_error($connection));
- }
- if(isset($_POST['update'])){
- $UpdateQuery = "UPDATE `students` SET `elected_subject`='$ElectedSubject'";
- mysql_query($UpdateQuery, $con);
- };
- ?>
- <h1><strong>Student Record</strong></h1>
- <table id = "result" class="data-table">
- <caption class="title"></caption>
- <thead>
- <tr>
- <th>Student ID</th>
- <th>Student Name</th>
- <th>Father Name</th>
- <th>Class</th>
- <th>Selected Subject</th>
- <th>View/Update</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $no = 1;
- $total = 0;
- while ($row = mysqli_fetch_array($query))
- {
- echo "<form action=update_students.php method=post>";
- $student = $row['stu_id'] == 0 ? '' : number_format($row['stu_id']);
- echo '<tr>
- <td>'.$row['student_id'].'</td>
- <td>'.$row['student_name'].'</td>
- <td>'.$row['father_name'].'</td>
- <td>'.$row['class'].'</td>
- <td>'.$row['elected_subject'].'</td>
- <td>' . "<input type='submit' name='update' value='update'>" . '</td>
- </tr>';
- $total += $row['stu_id'];
- $no++;
- }?>
- </tbody>
- </table>
Add Comment
Please, Sign In to add comment