Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- $file = 'numerical_index.txt';
- $book = file('formatted/' . $file, FILE_SKIP_EMPTY_LINES);
- $out = null;
- $disp = '';
- for($i = 0; $i < count($book); $i++) {
- $str = explode('::', $book[$i]);
- $str = trim($str[1]);
- if(!empty($str)) {
- $out[] .= $str;
- $disp .= $str . "\n";
- }
- }
- $username = 'test';
- $password = 'abc123';
- $host = '127.0.0.1';
- $database = 'book';
- if(isset($_POST['submit']) && !empty($_POST['submit'])) {
- $dbh = new mysqli($host, $username, $password, $database);
- if($dbh) {
- $sql = 'INSERT INTO appendixes VALUES (?, ?)';
- $stmt = $dbh->prepare($sql);
- $stmt->bind_param('is', $id, $name);
- for($i=0; $i < count($out); $i++) {
- $id = '';
- $name = $out[$i];
- $stmt->execute();
- if($stmt->error) { die($stmt->error); }
- }
- $stmt->close();
- echo 'Successfully added ' . $i . ' rows!';
- }
- }
- ?>
- <html>
- <head><title>Add Final Text</title></head>
- <body>
- <form method="post" action="">
- <input type="submit" name="submit" value="Submit" />
- </form>
- <br />
- <pre><?php echo $disp; ?></pre>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement