Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_POST['submit']) && !empty($_POST['query'])){
- $query = $_POST['query'];
- mysql_query($query);
- }
- ?>
- <form action="" method="post">
- <div>
- <textarea name="query"></textarea>
- <input type="submit" name="submit" value="submit" />
- </div>
- </form>
- <?php
- /* query.php */
- $query = $_REQUEST['query']; //do SQLi prevention
- $conn = new mysqli('localhost', 'root', '', 'db');
- if($conn->connect_error) throw new Exception('Failed to connect to MySQL server.'); //have the script handle the exception elsewhere
- if($conn->query($query) !== false)
- {
- echo 'Query executed successfully.';
- }
- $conn->close();
- <!DOCTYPE html>
- <!-- index.html -->
- <html>
- <head>
- </head>
- <body>
- <form method='POST' action='query.php'>
- <input type='text' name='query' />
- <br />
- <input type='submit' />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement