Created
September 11, 2018 15:15
-
-
Save ericyork/20e3fc39ddc665ba0d627167f52b5e7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--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