Guest User

Untitled

a guest
Sep 11th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. <!--Build the HTML -->
  2. <form action="index.php" method="post">
  3. <input type="text" name="dbname">
  4. <input type="submit" value="Submit">
  5. </form>
  6. <!--Use JS to prevent form resubmission on refresh/back button -->
  7. <script>
  8. if ( window.history.replaceState ) {
  9. window.history.replaceState( null, null, window.location.href );
  10. }
  11. </script>
  12. <?php
  13. //Set up our variables
  14. $servername = "localhost";
  15. $dbname = $_POST["dbname"]; //pull the value from the form
  16. $username = "utrial";
  17. $password = "utrial1";
  18. // Create connection
  19. $conn = new mysqli($servername, $username, $password, $dbname);
  20. // Check connection
  21. if ($conn->connect_error) {
  22. die("<p>Connection failed: " . "<span class=\"error\">" . $conn->connect_error . "</span></p>");
  23. }
  24. echo "<p>You're currently connected to the database named: <span class=\"success\">$dbname</span></p>";
  25. ?>
Add Comment
Please, Sign In to add comment