Advertisement
Guest User

Untitled

a guest
May 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. $file = 'numerical_index.txt';
  4. $book = file('formatted/' . $file, FILE_SKIP_EMPTY_LINES);
  5.  
  6. $out = null;
  7. $disp = '';
  8. for($i = 0; $i < count($book); $i++) {
  9.    
  10.     $str = explode('::', $book[$i]);
  11.     $str = trim($str[1]);
  12.     if(!empty($str)) {
  13.        
  14.         $out[] .= $str;
  15.         $disp .= $str . "\n";
  16.     }
  17. }
  18. $username = 'test';
  19. $password = 'abc123';
  20. $host = '127.0.0.1';
  21. $database = 'book';
  22.  
  23. if(isset($_POST['submit']) && !empty($_POST['submit'])) {
  24.    
  25.     $dbh = new mysqli($host, $username, $password, $database);
  26.    
  27.     if($dbh) {
  28.         $sql = 'INSERT INTO appendixes VALUES (?, ?)';
  29.        
  30.         $stmt = $dbh->prepare($sql);
  31.        
  32.         $stmt->bind_param('is', $id, $name);
  33.        
  34.         for($i=0; $i < count($out); $i++) {
  35.             $id = '';
  36.             $name = $out[$i];
  37.             $stmt->execute();
  38.             if($stmt->error) { die($stmt->error); }
  39.         }
  40.         $stmt->close();
  41.         echo 'Successfully added ' . $i . ' rows!';
  42.     }
  43. }
  44. ?>
  45. <html>
  46. <head><title>Add Final Text</title></head>
  47. <body>
  48. <form method="post" action="">
  49. <input type="submit" name="submit" value="Submit" />
  50. </form>
  51. <br />
  52. <pre><?php echo $disp; ?></pre>
  53. </body>
  54. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement