Advertisement
ridyko

input.php ( Cara CRUD )

Feb 1st, 2022
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.29 KB | None | 0 0
  1. <?php
  2.     if (isset($_POST['submit'])) {
  3.         require_once("koneksi.php");
  4.         $sql = $conn->prepare("INSERT INTO tbl_mahasiswa (nimmhs,namamhs,alamatmhs,teleponmhs,jurusanmhs) VALUES (?, ?, ?, ?, ?)");  
  5.         $nimmhs=$_POST['nimmhs'];
  6.         $namamhs = $_POST['namamhs'];
  7.         $alamatmhs= $_POST['alamatmhs'];
  8.         $teleponmhs= $_POST['teleponmhs'];
  9.         $jurusanmhs= $_POST['jurusanmhs'];
  10.         $sql->bind_param("sssss", $nimmhs, $namamhs, $alamatmhs, $teleponmhs, $jurusanmhs);
  11.         if($sql->execute()) {
  12.             $success_message = "Input Data Berhasil";
  13.         } else {
  14.             $error_message = "Ada masalah dengan Penginputan";
  15.         }
  16.         $sql->close();  
  17.         $conn->close();
  18.     }
  19. ?>
  20. <html>
  21. <head>
  22. <link href="style.css" rel="stylesheet" type="text/css" />
  23.    
  24. <style>
  25. .tbl-qa{border-spacing:0px;border-radius:4px;border:#6ab5b9 1px solid;}
  26. </style>
  27.   <title>Input Data Mahasiswa</title>  
  28. </head>
  29. <body>
  30. <h1>CRUD PHP MySQLi questkomputer.com</h1>
  31. <?php if(!empty($success_message)) { ?>
  32. <div class="success message"><?php echo $success_message; ?></div>
  33. <?php } if(!empty($error_message)) { ?>
  34. <div class="error message"><?php echo $error_message; ?></div>
  35. <?php } ?>
  36. <form id="frmUser" method="post" action="">
  37. <div class="button_link"><a href="index.php"> List Mahasiswa </a></div>
  38. <table border="0" cellpadding="10" cellspacing="0" width="500" align="center" class="tbl-qa">
  39.     <thead>
  40.         <tr>
  41.             <th colspan="2" class="table-header">Input Data Mahasiswa</th>
  42.         </tr>
  43.     </thead>
  44.     <tbody>
  45.         <tr class="table-row">
  46.             <td><label>NIM</label></td>
  47.             <td><input type="text" name="nimmhs" class="txtField"></td>
  48.         </tr>
  49.         <tr class="table-row">
  50.             <td><label>Nama</label></td>
  51.             <td><input type="text" name="namamhs" class="txtField"></td>
  52.         </tr>
  53.         <tr class="table-row">
  54.             <td><label>Alamat</label></td>
  55.             <td><input type="text" name="alamatmhs" class="txtField"></td>
  56.         </tr>
  57.         <tr class="table-row">
  58.             <td><label>Telepon</label></td>
  59.             <td><input type="text" name="teleponmhs" class="txtField"></td>
  60.         </tr>
  61.         <tr class="table-row">
  62.             <td><label>Jurusan</label></td>
  63.             <td><input type="text" name="jurusanmhs" class="txtField"></td>
  64.         </tr>
  65.         <tr class="table-row">
  66.             <td colspan="2"><input type="submit" name="submit" value="Submit" class="demo-form-submit"></td>
  67.         </tr>
  68.     </tbody>
  69. </table>
  70. </form>
  71. </body>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement