Advertisement
henka04

bind_param

Feb 21st, 2016
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.37 KB | None | 0 0
  1. <?php
  2. include('connect.php');
  3. ?>
  4.  
  5. <fieldset>
  6.   <legend>Masukan Data</legend>
  7.     <form action="tambah.php" method="post" enctype="multipart/form-data">
  8.       Nama Sepeda :<input type="text" name="nama_sepeda">
  9.       Size Sepeda :<input type="text" name="size_sepeda">
  10.       Harga Sepeda:<input type="text" name="harga_sepeda">
  11.       <input type="file" name="gambar">
  12.       <input type="submit" name="tambah" value="Tambahkan">
  13.     </form>
  14. </fieldset>
  15. <?php
  16. if(isset($_POST['tambah'])){
  17. $data = array (
  18.               'nama_sepeda' => $_POST['nama_sepeda'],
  19.               'size_sepeda' => $_POST['size_sepeda'],
  20.               'harga_sepeda'=> $_POST['harga_sepeda'],
  21.               'gambar' => $_FILES['gambar']['name'],
  22.             );
  23. $key = implode(",",array_keys($data));
  24.  
  25. $i=0;
  26. foreach ($data as $key => $value) {
  27.   if(is_int($value)){
  28.     $nilaidata[$i] = $value;
  29.   }else{
  30.     $nilaidata[$i] = "'".$value."'";
  31.   }
  32.   $i++;
  33. }
  34. $hasilnilai = implode(",",$nilaidata);
  35. $tempatgambar = $_FILES['gambar']['tmp_name'];
  36. $namagambar = $_FILES['gambar']['name'];
  37. move_uploaded_file($tempatgambar,"gambar/".$namagambar);
  38.  
  39. $query = $db->prepare("INSERT INTO sepeda ($key) VALUES (?)");
  40. $query->bind_param('ssib',$hasilnilai);
  41. $query->execute();
  42.  
  43. if($query){
  44.   echo "data tersimpan";
  45. }else{
  46.   echo "data gagal tersimpan";
  47. }
  48.  
  49. $query->close();
  50. $db->close();
  51. }
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement