Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Find your words</title>
- <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
- </head>
- <body>
- <?php
- ////////////////////////////////////////////////////////////
- //////// script created by Shady on GNU/GPL license ////////
- //////// gg 15530223 | mail izzypjchamp@gmail.com ////////
- ////////////////////////////////////////////////////////////
- /***********************************************************
- CREATE TABLE IF NOT EXISTS `results` (
- `find` varchar(50) COLLATE utf8_polish_ci NOT NULL,
- `value` varchar(50) COLLATE utf8_polish_ci NOT NULL,
- PRIMARY KEY (`find`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
- INSERT INTO `results` (`find`, `value`) VALUES
- ('from', 'to'),
- ('to2', 'from2');
- ***********************************************************/
- try {
- $db = new PDO('mysql:host=localhost;dbname=table_name;charset=utf8', 'user', 'pass',
- array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
- $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- if (isset($_GET['add'])) {
- if (isset($_POST['new'])) {
- $new = explode("\n", $_POST['new']);
- $i = 0;
- $max = sizeof($new);
- while ($i < $max) {
- $record = explode('-', $new[$i]);
- $db->exec("INSERT INTO `results` SET `find` = '".trim($record[0])."', `value` = '".trim($record[1])."'");
- $i++;
- }
- echo 'poprawnie dodano '.$max.' nowych rekordów (:<br/><br/>';
- unset($_POST);
- }
- echo '<form action="#" method="POST">
- <textarea name="new"></textarea>
- <input type="submit" value="Add" />
- </form>';
- } else {
- if (isset($_POST['find'])) {
- $query = $db -> prepare("SELECT `find`, `value` FROM `results` WHERE `find` = :find OR `value` = :find LIMIT 1");
- $query -> bindValue(':find', trim($_POST['find']), PDO::PARAM_STR);
- $query -> execute();
- $result = $query -> fetch();
- $query -> closeCursor();
- echo $result['value'] ? 'wynik: '.($_POST['find'] == $result['value'] ?
- $result['find'].'<br/><br/>' :
- $result['value']).'<br/><br/>'
- : 'nie zaleziono pasujacego zamiennika<br/><br/>';
- }
- echo '<form action="#" method="POST">
- <input type="text" name="find" />
- <input type="submit" value="Go" />
- </form>';
- }
- } catch (PDOException $error) {
- echo 'db error: '.$error->getMessage();
- }
- echo isset($_GET['add']) ?
- '<a href="words.php" style="color: #000; text-decoration: none">- powrót do wyszukiwania' :
- '<a href="?add=true" style="color: #000; text-decoration: none">+ dodaj nowe slówka</a>';
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement