Guest User

borang_ayam_proses2

a guest
Nov 13th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. //echo '<pre>'; print_r($_POST) . '</pre>';
  3.  
  4. $host        =    'localhost';
  5. $user        =    'dbayam';
  6. $password    =    'pwdayamdb';
  7. $database    =    'ayam';
  8. $conn        =    mysql_connect($host,$user,$password) or die('Server Information is not Correct');
  9. mysql_select_db($database,$conn) or die('Database Information is not correct');
  10.  
  11. /*
  12. Contoh sql yang sepatutnya
  13.  
  14. INSERT INTO serama_a
  15. (sangkar,gaya,tubuh,ekor,balung,sayap,bulu,warna,kaki,lawi)
  16. VALUES
  17. ('$sangkar','$gaya','$tubuh','$ekor','$balung','$sayap','$bulu','$warna','$kaki','$lawi'),
  18. ('$sangkar','$gaya','$tubuh','$ekor','$balung','$sayap','$bulu','$warna','$kaki','$lawi'),
  19. ('$sangkar','$gaya','$tubuh','$ekor','$balung','$sayap','$bulu','$warna','$kaki','$lawi'),
  20. ('$sangkar','$gaya','$tubuh','$ekor','$balung','$sayap','$bulu','$warna','$kaki','$lawi'),
  21. ('$sangkar','$gaya','$tubuh','$ekor','$balung','$sayap','$bulu','$warna','$kaki','$lawi')
  22. */
  23.  
  24. $isi = null;
  25. $jumlah_key = count($_POST['serama_a']);
  26. $sql ="\rINSERT INTO serama_a \r";
  27.        
  28. foreach ($_POST['serama_a'] as $key=>$data)
  29. {
  30.     $tajuk = '(`' . implode('`, `', array_keys($data)) . '`)' .
  31.     "\rVALUES\r";
  32.  
  33.     $isi .= '("' . implode('", "', array_values($data)) . '")';
  34.     $isi .= ($key == $jumlah_key) ? "\r" : ",\r";  
  35. }
  36.        
  37. echo 'Jumlah key = ' . $jumlah_key . '<br><pre>' .
  38. $sql . $tajuk . $isi . '<br></pre>';
Advertisement
Add Comment
Please, Sign In to add comment