Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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 and Save" />
- </form>
- </body>
- </html>
- <?php session_start();
- if (isset($_POST['addTable']) && isset($_POST['removeTable']))
- {
- $_SESSION['addTable'] = $_POST['addTable'];
- $_SESSION['removeTable'] = $_POST['removeTable'];
- $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();
- }
- $SQLaddTable = "CREATE TABLE example(
- id INT NOT NULL AUTO_INCREMENT,
- PRIMARY KEY(id),
- name VARCHAR(30),
- age INT)";
- try {
- $dbh->query($SQLaddTable);
- echo "Table successfully created.";
- }catch (Exception $e) {
- echo "{$_SESSION['addTable']} could not be added." , $e->getMessage(),"\n";
- }
- $SQLremoveTable = "DROP TABLE {$_SESSION['removeTable']}";
- try {
- $dbh->query($SQLremoveTable);
- }catch (Exception $e) {
- echo "{$_SESSION['removeTable']} could not removed." , $e->getMessage() , "\n";
- }
- $dbh = null;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement