Advertisement
oke_google

update_php

Feb 12th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.55 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <meta charset="utf-8">
  5.     <title>INPUT INSERT PDO</title>
  6.   </head>
  7.   <body>
  8.   <?php
  9.   require "koneksi.php";
  10.   ?>
  11.   <form method="get">
  12.   <table>
  13.   <tr><td>NPM Terdaftar</td><td><input width="200px" name="npm" placeholder="Masukan NPM"></input></td></tr>
  14.   </table>
  15.   <button type="submit">oke</button>
  16.   </form>
  17.  
  18. <?php
  19. try {
  20.    $DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  21.    $STH = $DBH->prepare("SELECT * FROM mahasiswa WHERE npm = :npm");
  22.    $npm = $_GET["npm"];
  23.    $STH -> bindParam(':npm', $npm);
  24.    $STH -> execute();
  25.    while($row = $STH->fetch()) {
  26.      echo "NPM = ".$row[0]."<br>";
  27.      echo "NAMA = ".$row[1]."<br>";
  28.      echo "semester = ".$row[2]."<br>";
  29.      echo "umur = ".$row[3]."<br>";
  30.      echo "<br><br>";
  31.    }
  32.  
  33.    // hapus koneksi
  34.    $dbh = null;
  35. }
  36. catch (PDOException $e) {
  37.    // tampilkan pesan kesalahan jika koneksi gagal
  38.    print "Koneksi atau query bermasalah: " . $e->getMessage() . "<br/>";
  39.    die();
  40. }
  41. ?>
  42.  
  43. <form method="POST" action="update_PDO.php">
  44. <table>
  45. <tr><td>NPM Terdaftar</td><td><input width="200px" name="npm" placeholder="Masukan NPM"></input></td></tr>
  46. <tr><td>Nama</td><td><input width="200px" name="nama" placeholder="Masukan nama"></input></td></tr>
  47. <tr><td>Semester</td><td><input width="200px" name="semester" placeholder="Masukan Semester"></input></td></tr>
  48. <tr><td>Umur</td><td><input width="200px" name="umur" placeholder="Masukan umur"></input></td></tr>
  49. </table>
  50. <button type="submit">oke</button>
  51. </form>
  52.   </body>
  53. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement