Advertisement
GWibisono

masukin data dari excel ke mysql

May 26th, 2012
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  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>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement