Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['submit']) && !empty($_POST['query'])){
  3. $query = $_POST['query'];
  4. mysql_query($query);
  5.  
  6. }
  7.  
  8. ?>
  9.  
  10. <form action="" method="post">
  11. <div>
  12. <textarea name="query"></textarea>
  13. <input type="submit" name="submit" value="submit" />
  14. </div>
  15. </form>
  16.  
  17. <?php
  18.  
  19. /* query.php */
  20. $query = $_REQUEST['query']; //do SQLi prevention
  21. $conn = new mysqli('localhost', 'root', '', 'db');
  22. if($conn->connect_error) throw new Exception('Failed to connect to MySQL server.'); //have the script handle the exception elsewhere
  23. if($conn->query($query) !== false)
  24. {
  25. echo 'Query executed successfully.';
  26. }
  27. $conn->close();
  28.  
  29. <!DOCTYPE html>
  30. <!-- index.html -->
  31. <html>
  32. <head>
  33. </head>
  34. <body>
  35. <form method='POST' action='query.php'>
  36. <input type='text' name='query' />
  37. <br />
  38. <input type='submit' />
  39. </form>
  40. </body>
  41. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement