Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. <html>
  2. <body>
  3.  
  4. <form action = "test.php" method = "post">;
  5. "Query to run (1)?" <input name = "input1" type = "text" /><br>
  6. "Query to run (2)?" <input name = "input2" type = "text" />
  7. <input type = "submit" name = 'submit' value = 'go'/>
  8. </form>
  9.  
  10. <?php
  11.  
  12. //we want all errors.
  13. error_reporting(E_ALL);
  14. ini_set('display_errors', 1);
  15.  
  16. $host = 'localhost';
  17. $db = 'hatchery';
  18. $user = 'hatchery';
  19. $pass = 'hatchery';
  20. $charset = 'utf8mb4';
  21.  
  22. $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
  23.  
  24. $opt = [
  25. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  26. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  27. PDO::ATTR_EMULATE_PREPARES => false,
  28. ];
  29. $pdo = new PDO($dsn, $user, $pass, $opt);
  30.  
  31. //let's print the rows of a given sql
  32. function printRows($pdo, $sql, $query_index){
  33. if(empty($sql)){
  34. echo "<br>The query #{$query_index} is empty!<br>";
  35. return;
  36. }
  37. foreach ($pdo->query($sql) as $row) {
  38. var_dump($row);
  39. }
  40. }
  41.  
  42. //did the user click the "submit" button?
  43. if(!empty($_POST['submit'])){
  44. //no sanitizize at all:
  45. printRows($pdo, $_POST['input1'],1);
  46. printRows($pdo, $_POST['input2'],2);
  47. }
  48. ?>
  49. </body>
  50. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement