Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ubah variable dibawah
- $db_user = 'root';
- $db_pass = 'password';
- $db_name = 'namaDB';
- // connect to database
- $dsn = 'mysql:dbname=' . $db_name . ';charset=utf8;host=localhost';
- try {
- $dbh = new PDO( $dsn, $db_user, $db_pass );
- } catch ( PDOException $e ) {
- echo 'Connection failed: ' . $e->getMessage();
- }
- // action when posted
- if ( $_POST ) {
- $table = 'order'; // ubah ke nama tabel
- $field = 'id,pesanan'; // kolomnya, kalo > 1 pisahkan pakai koma
- $val = '?,?'; // ini sesuai jumlah kolomnya, pakai koma
- $array = array( $_POST['id'], $_POST['pesanan'] ); // sesuai jumlah kolom juga
- $sth = $dbh->prepare( "INSERT INTO $table ($field) VALUES ($val)" );
- $r = $sth->execute( $array );
- echo ( $r ) ? 'Pesanan sudah disimpan.' : 'Gagal menyimpan pesanan.';
- }
- ?>
- <form method="post">
- <input type="text" name="pesanan"><!-- Tambahin input nya sesuai kebutuhan -->
- <button type="submit">Pesan</button>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement