How to connect to the database using php

$servername = "localhost"; //name of the server you're connecting
$username = "dcmrfnet_admin"; //username of the database 
$password = "kuoWAeUxVdQqps1"; //password of that database user
$dbname = "dcmrfnet_database1"; //database name

$mysqli = new mysqli($servername, $username, $password, $dbname);

//Checks database connection
if ($mysqli->connect_errno) {
    echo "Connect failed. ERROR: ". $mysqli->error;
    exit();
}

How to get all database content using php

// CODE TO THE DISPLAY STUDENT DETAILS
$query = "SELECT * FROM student";
if ($result = $mysqli->query($query)) {
    while ($row = $result->fetch_assoc()) {
      $show_students .= '<tr><td>'.$row["stud_id"].'</td>';
      $show_students .= '<td>'.$row["fname"].'</td>';
      $show_students .= '<td>'.$row["lname"].'</td></tr>';
    }
    $result->free();
}
OUTPUT:

Student ID First Name Last Name
5GregSully

How insert content to the database using php

// CODE TO THE ADD NEW STUDENT
if (isset($_POST['submit'])) { //checks if the SUBMIT button is clicked
  $fname = $_POST['first_name']; //gets the value in FIRST NAME box
  $lname = $_POST['last_name']; //gets the value in LAST NAME box

  $query = 'INSERT INTO student (fname, lname) VALUES ("'.$fname.'","'.$lname.'")';

  if ($mysqli->query($query) === TRUE) {
    header( "refresh:2;url=/database1" );
    echo 'New record added successfully!';
  } else {
    echo "Error adding student. ERROR: ". $mysqli->error;
  }
}
OUTPUT:

Add New Student

First Name:

Last Name:


How to delete a record from the database using php

// CODE TO DELETE A STUDENT
if (isset($_POST['delete'])){ //checks if the DELETE button is clicked
  $student_id = $_POST['student_']; 

  if($student_id !=''){
    $del = "DELETE FROM student WHERE stud_id=".$student_id;

    if ($mysqli->query($del) === TRUE) {
      header( "refresh:1;url=/database1" ); 
      echo 'Student deleted successfully!'; 
      exit;
    } else {
      echo "Error deleting a record: " . $mysqli->error;
    }
  }
}
OUTPUT:

Delete a Student

Student Names: