Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php session_start() ?>
- <html>
- <head><title>User Dashboard</title></head>
- <body><center><h3>Welcome to your Dashboard!</h3></center>
- <form name="Form2" method="post" action="dashboard.php">
- Add Table: <input type="text" name="addTable"/>
- Remove Table: <input type="text" name="removeTable" />
- <input type="submit" name="Submit" />
- </form>
- </body>
- </html>
- <?php
- $dsn = "mysql:dbname={$_SESSION['dbname']}" ; "host=localhost";
- $user = "{$_SESSION['username']}";
- $password = "{$_SESSION['password']}";
- try {
- $dbh = new PDO($dsn, $user, $password);
- } catch (PDOException $e) {
- echo 'Connection failed : ' , $e->getMessage();
- }
- if (isset($_POST['addTable']))
- {
- $addTable = $_POST['addTable'];
- $SQLaddTable = "CREATE TABLE $addTable(
- id INT NOT NULL AUTO_INCREMENT,
- PRIMARY KEY(id),
- name VARCHAR(30),
- age INT)";
- try {
- $dbh->query($SQLaddTable);
- echo "The $addTable table was successfully created.";
- }catch (Exception $e) {
- echo "$addTable could not be added." , $e->getMessage(),"\n";
- }
- }
- else if (isset($_POST['removeTable']))
- {
- $removeTable = $_POST['removeTable'];
- $SQLremoveTable = "DROP TABLE $removeTable";
- try {
- $dbh->query($SQLremoveTable);
- echo "The $removeTable table was successfully removed.";
- }catch (Exception $e) {
- echo "$removeTable could not removed." , $e->getMessage() , "\n";
- }
- }
- $dbh = null;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement