Guest User

Untitled

a guest
Dec 9th, 2018
1,423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $db = "db_nilai_mahasiswa";
  6.  
  7. $nim = $_POST["nim"];
  8. $nama = $_POST["nama"];
  9. $prodi = $_POST["program_studi"];
  10. $matkul = $_POST["mata_kuliah"];
  11. $sks = $_POST["sks"];
  12. $nilai = $_POST["nilai"];
  13.  
  14. //Create connection to db
  15. $connection = mysqli_connect($servername, $username, $password, $db);
  16.  
  17. //Check connection to db
  18. if (!$connection) {
  19. die("Connection failed: " . mysqli_connect_error());
  20. }
  21.  
  22. //Aware data type
  23. if ($nilai >= 85 || $nilai == 100) {
  24. $grade = 'A';
  25. } else if ($nilai >= 75 || $nilai == 84) {
  26. $grade = 'B';
  27. } else if ($nilai >= 60 || $nilai == 74) {
  28. $grade = 'C';
  29. } else if ($nilai >= 50 || $nilai == 59) {
  30. $grade = 'D';
  31. } else {
  32. $grade = 'E';
  33. }
  34.  
  35. $insert = "INSERT INTO mahasiswa (nim, nama, program_studi, mata_kuliah, sks, nilai, grade)
  36. VALUES ('$nim', '$nama', '$prodi', '$matkul', '$sks', '$nilai', '$grade')";
  37.  
  38. if (mysqli_query($connection, $insert)) {
  39. header("location:SelectData.php");
  40. } else {
  41. echo "Data tidak berhasil dimasukkan : " . $insert . "<br>" . mysqli_error($connection);
  42. }
  43.  
  44. mysqli_close($connection);
  45. ?>
Add Comment
Please, Sign In to add comment