Don't like ads? PRO users don't see any ads ;-)

masukin data dari excel ke mysql

By: GWibisono on May 26th, 2012  |  syntax: PHP  |  size: 0.89 KB  |  hits: 36  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /*
  3. lupa ngasi if
  4. */
  5. if($_POST){
  6. include('config.php');
  7. /*
  8. disini setting mysql dan koneksi terjadi
  9. pastikan field lebih dari 2!!
  10. */
  11. $a=explode("\n",$_POST['txt']);
  12. $table=trim($_POST['table']);
  13. foreach($a as $v)
  14. {
  15.        
  16.         $a2=explode("\t", $v);
  17.         if(count($a2)<2) continue;
  18.         $sql="insert into $table values('$a2[0]'";
  19.         for($i=1;$i<count($a2)){
  20.                 $sql.=",\n'".trim(addslashes($a2[$i]))."'";
  21.         }
  22.         $sql.=")";
  23.         //jalankan perintah sql disini
  24.        
  25.         //optional tp gw lebih suka ada.. buat laporan sampe mana
  26.         echo "<br>input $a2[0]";
  27. }
  28.  
  29. exit();
  30. }
  31. ?>
  32. <form action="?" method="post" enctype="multipart/form-data" target="_self" >
  33. BUKA XLS.. copy semua data (block) di worksheet tersebut
  34. <b>copy disini</b><br>
  35.     <textarea cols="45" name='txt'></textarea>
  36. <br>Nama table
  37. <br><input type=text name=table>       
  38.     <input type="submit" name="button" id="button" value="Submit" />
  39.         </form>