Advertisement
ridyko

edit.php ( Cara CRUD )

Feb 1st, 2022
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.45 KB | None | 0 0
  1. <?php
  2.     require_once("koneksi.php");
  3.     if (isset($_POST['submit'])) {     
  4.         $sql = $conn->prepare("UPDATE tbl_mahasiswa SET namamhs=? , alamatmhs=? , teleponmhs=? , jurusanmhs=? WHERE nimmhs=?");
  5.         $namamhs=$_POST['namamhs'];
  6.         $alamatmhs = $_POST['alamatmhs'];
  7.         $teleponmhs= $_POST['teleponmhs'];
  8.         $jurusanmhs= $_POST['jurusanmhs'];
  9.         $sql->bind_param("sssss",$namamhs, $alamatmhs, $teleponmhs, $jurusanmhs,$_GET["nimmhs"]);  
  10.         if($sql->execute()) {
  11.             $success_message = "Update Data Berhasil";
  12.         } else {
  13.             $error_message = "Ada masalah update data";
  14.         }
  15.  
  16.     }
  17.     $sql = $conn->prepare("SELECT * FROM tbl_mahasiswa WHERE nimmhs=?");
  18.     $sql->bind_param("s",$_GET["nimmhs"]);         
  19.     $sql->execute();
  20.     $result = $sql->get_result();
  21.     if ($result->num_rows > 0) {       
  22.         $row = $result->fetch_assoc();
  23.     }
  24.     $conn->close();
  25. ?>
  26. <html>
  27. <head>
  28. <link href="style.css" rel="stylesheet" type="text/css" />
  29. <style>
  30. .tbl-qa{border-spacing:0px;border-radius:4px;border:#6ab5b9 1px solid;}
  31. </style>
  32. <title>JavanetMedia - Edit Mahasiswa </title>
  33. </head>
  34. <body>
  35. <?php if(!empty($success_message)) { ?>
  36. <div class="success message"><?php echo $success_message; ?></div>
  37. <?php } if(!empty($error_message)) { ?>
  38. <div class="error message"><?php echo $error_message; ?></div>
  39. <?php } ?>
  40. <form name="frmUser" method="post" action="">
  41. <div class="button_link"><a href="index.php" > List Mahasiswa </a></div>
  42. <table border="0" cellpadding="10" cellspacing="0" width="500" align="center" class="tbl-qa">
  43.     <thead>
  44.         <tr>
  45.             <th colspan="2" class="table-header">Edit Data Mahasiswa</th>
  46.         </tr>
  47.     </thead>
  48.     <tbody>
  49.         <tr class="table-row">
  50.             <td><label>Nama</label></td>
  51.             <td><input type="text" name="namamhs" class="txtField" value="<?php echo $row["namamhs"]?>"></td>
  52.         </tr>
  53.         <tr class="table-row">
  54.             <td><label>Alamat</label></td>
  55.             <td><input type="text" name="alamatmhs" class="txtField" value="<?php echo $row["alamatmhs"]?>"></td>
  56.         </tr>
  57.         <tr class="table-row">
  58.             <td><label>Telepon</label></td>
  59.             <td><input type="text" name="teleponmhs" class="txtField" value="<?php echo $row["teleponmhs"]?>"></td>
  60.         </tr>
  61.         <tr class="table-row">
  62.             <td><label>Jurusan</label></td>
  63.             <td><input type="text" name="jurusanmhs" class="txtField" value="<?php echo $row["jurusanmhs"]?>"></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