Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <body>
- <form action = "test.php" method = "post">;
- "Query to run (1)?" <input name = "input1" type = "text" /><br>
- "Query to run (2)?" <input name = "input2" type = "text" />
- <input type = "submit" name = 'submit' value = 'go'/>
- </form>
- <?php
- //we want all errors.
- error_reporting(E_ALL);
- ini_set('display_errors', 1);
- $host = 'localhost';
- $db = 'hatchery';
- $user = 'hatchery';
- $pass = 'hatchery';
- $charset = 'utf8mb4';
- $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
- $opt = [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- PDO::ATTR_EMULATE_PREPARES => false,
- ];
- $pdo = new PDO($dsn, $user, $pass, $opt);
- //let's print the rows of a given sql
- function printRows($pdo, $sql, $query_index){
- if(empty($sql)){
- echo "<br>The query #{$query_index} is empty!<br>";
- return;
- }
- foreach ($pdo->query($sql) as $row) {
- var_dump($row);
- }
- }
- //did the user click the "submit" button?
- if(!empty($_POST['submit'])){
- //no sanitizize at all:
- printRows($pdo, $_POST['input1'],1);
- printRows($pdo, $_POST['input2'],2);
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement