1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<?php include("koneksi.php"); ?> <html> <head> <title>Tambah</title> <link rel="stylesheet" type="text/css" href="gaya.css"> </head> <body> <?php include('menu.php'); echo '<p>Menambah satu record baru</p>'; $username = isset($_POST['username']) ? $_POST['username'] : ""; $password = isset($_POST['password']) ? $_POST['password'] : ""; $nama = isset($_POST['nama']) ? $_POST['nama'] : ""; $lahir = isset($_POST['lahir']) ? $_POST['lahir'] : ""; $nilai = isset($_POST['nilai']) ? $_POST['nilai'] : ""; $stmt = $pdo->prepare('INSERT INTO tugas1 VALUES (?,?,?,?,?)'); if ($stmt->execute([$username, md5($password), $nama, $lahir, $nilai])) { echo "<p>Sukses! Data telah direkam.</p>"; } else { echo "<p>Gagal menyimpan ke tabel.</p>"; } ?> </body> </html> |
Perintah $stmt->execute() akan mengembalikan nilai FALSE bia perintah SQL yang diéksekusi mengalami kegagalan.