Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('connect.php');
- ?>
- <fieldset>
- <legend>Masukan Data</legend>
- <form action="tambah.php" method="post" enctype="multipart/form-data">
- Nama Sepeda :<input type="text" name="nama_sepeda">
- Size Sepeda :<input type="text" name="size_sepeda">
- Harga Sepeda:<input type="text" name="harga_sepeda">
- <input type="file" name="gambar">
- <input type="submit" name="tambah" value="Tambahkan">
- </form>
- </fieldset>
- <?php
- if(isset($_POST['tambah'])){
- $data = array (
- 'nama_sepeda' => $_POST['nama_sepeda'],
- 'size_sepeda' => $_POST['size_sepeda'],
- 'harga_sepeda'=> $_POST['harga_sepeda'],
- 'gambar' => $_FILES['gambar']['name'],
- );
- $key = implode(",",array_keys($data));
- $i=0;
- foreach ($data as $key => $value) {
- if(is_int($value)){
- $nilaidata[$i] = $value;
- }else{
- $nilaidata[$i] = "'".$value."'";
- }
- $i++;
- }
- $hasilnilai = implode(",",$nilaidata);
- $tempatgambar = $_FILES['gambar']['tmp_name'];
- $namagambar = $_FILES['gambar']['name'];
- move_uploaded_file($tempatgambar,"gambar/".$namagambar);
- $query = $db->prepare("INSERT INTO sepeda ($key) VALUES (?)");
- $query->bind_param('ssib',$hasilnilai);
- $query->execute();
- if($query){
- echo "data tersimpan";
- }else{
- echo "data gagal tersimpan";
- }
- $query->close();
- $db->close();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement