Skip to content

Instantly share code, notes, and snippets.

@ericyork
Created September 11, 2018 15:15
Show Gist options
  • Save ericyork/20e3fc39ddc665ba0d627167f52b5e7e to your computer and use it in GitHub Desktop.
Save ericyork/20e3fc39ddc665ba0d627167f52b5e7e to your computer and use it in GitHub Desktop.
<!--Build the HTML -->
<form action="index.php" method="post">
<input type="text" name="dbname">
<input type="submit" value="Submit">
</form>
<!--Use JS to prevent form resubmission on refresh/back button -->
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
//Set up our variables
$servername = "localhost";
$dbname = $_POST["dbname"]; //pull the value from the form
$username = "utrial";
$password = "utrial1";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("<p>Connection failed: " . "<span class=\"error\">" . $conn->connect_error . "</span></p>");
}
echo "<p>You're currently connected to the database named: <span class=\"success\">$dbname</span></p>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment